Let String s= “1A”
and I want to assign equivalent HEX value 1A or DEC value 26 to a integer.
What are some efficient way of doing it?
like to decimal to string conversion is done by
char c[10];
sprintf(c, “%d”, integer_value);
is there similar way of doing that?
- Hex string to integer: sscanf(c, “%x”, &integer_value);
After this “integer_value” will contain hex equivalent of cstring “c”.
- Hexa decimal to string: sprintf(c, “%x”, integer_value);
After this “c” will contain hex equivalent of decimal intger_value.
Example: http://ideone.com/XYdsf5
If you want to convert it from “string” class then first convert to cstring, by S.c_str() method,
then do step 1 or 2
2 Likes