MASSIVE EDIT:
I have a long int variable that I need to convert to a signed 24-bit hexadecimal string without "0x" at the beginning. The string must be 6 characters, followed by the string delimiter '\ 0', so leading zeros must be added.
Examples: [-1 β FFFFFF] --- [1 β 000001] --- [71 β 000047]
Answer
This looks like a trick:
long int number = 37;
char string[7];
snprintf (string, 7, "%lX", number);
source
share