Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Wed Dec 17, 2014 8:10 am |
|
|
Assuming string is called 'source':
Code: |
int8 ctr=0;
char destination[15] = {""};
char temp[3];
while (source[ctr]!='\0')
{
sprintf(temp,"%02X",source[ctr++]);
strcat(destination,temp);
}
|
Various things. The initialisation of 'destination' is needed so it contains a null terminator or strcat won't work. Within the limits of the size of 'destination', this handles any length string, till it sees the null terminator.
It just converts character by character, and builds the destination up.
The %02X format, forces every character to hex in the form XX two digits each time, with leading zeros.
Further comments, the 0x won't be put in the output, and the capital 'X' is needed to give the capital return you want. I made destination an odd size since it will hold two characters for each character in the input string, and a null terminator. |
|