How to cast from hexadecimal to string in C?
11,416
Solution 1
You cannot simply 'cast', you will need to use sprintf
to do the convertion:
unsigned int hex = 0xABC123FF;
char hexString[256];
sprintf(hexString, "0x%08X", hex);
If you want to 'cast' it to string in order to print it, you can use printf
directly:
unsigned int hex = 0xABC123FF;
printf("0x%08X", hex);
Solution 2
You cannot cast from a number to a string in C. You'll have to call a function for that purpose.
Author by
Ricardo
Updated on June 04, 2022Comments
-
Ricardo almost 2 years
How to cast from hexadecimal to string in C?