i need to convert a string to hexadecimal as follows :
String : "12345678"
needs to be converted to aHow Can that be done ?Code:char value[4] = { '0x12' ,'0x34' , '0x56' , '0x78'};
Thx
i need to convert a string to hexadecimal as follows :
String : "12345678"
needs to be converted to aHow Can that be done ?Code:char value[4] = { '0x12' ,'0x34' , '0x56' , '0x78'};
Thx
It appears you just did it
Look up sscanf() format specifiers. %2x 4 times in the format string will do it.
Thx for the reply ,
Actually i just wanted to show how i wanted the result to be. the actual string would be of variable length.so i need a function to transform the string characters to hexadecimal the way showed above.
As I said above, you can use sscanf() with an appropriate format string. In C++, a more idiomatic way would be to use string streams.
I'll leave it as an exercise to work out how to turn a hex digit (in the range '0' to '9' or the range 'A' to 'F') to a numeric value (0x0 to 0x9 or 0xA to 0xF).