How to cast from hexadecimal to string in C?

c, casting

Solution

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);

Problem

How to cast from hexadecimal to string in C?

Original source