I am trying to load 32-bit hexadecimal into char array.
#define NUC 0xA8051701
unsigned char debug_msg[100];
sprintf (debug_msg, "%08x", NUC);
But it is loading only "A805" that to as ASCII character instead of hexadecimal. Can any one suggest what could be the problem.
What I'm actually looking for is:
debug_msg[0]=0xA8
debug_msg[1]=0x05
debug_msg[2]=0x17
debug_msg[3]=0x01
Instead of the correct value, it is loading as below:
debug_msg[0]=0x30
debug_msg[1]=0x30
debug_msg[2]=0x30
debug_msg[3]=0x30
debug_msg[4]=0x61
debug_msg[5]=0x38
debug_msg[6]=0x30
debug_msg[7]=0x35
Effectively it is loading 0x0000a805 that to in ASCII.
sprintftakes achar *, e.g.char debug_msg[100];inton your machine? Is it a big-endian architecture? What do you actually want as the result? (I guess thatsizeof(int) == 2— 16 bits, and it is big-endian, and you wantdebug_msg[0] = 0xA8; debug_msg[1] = 0x05; debug_msg[2] = 0x17; debug_msg[3] = 0x01;— but that's guesswork. You should certainly explain what you want and it might help to identify the processor type and so on.)printf("%s",debug_msg);