MASSIVE EDIT:
I have a long int variable that I need to convert to a signed 24bit hexadecimal string without the "0x" at the start. The string must be 6 characters followed by a string terminator '\0', so leading zeros need to be added.
Examples: [-1 -> FFFFFF] --- [1 -> 000001] --- [71 -> 000047]
Answer This seems to do the trick:
long int number = 37;
char string[7];
snprintf (string, 7, "%lX", number);
Look at sprintf
. The %lx
specifier does what you want.