I have an array like this:
unsigned char arr[] = {0x55};
unsigned char byte = arr[0];
And I want to have byte be the hex representation, just like it is in the array.
But when I look at it in gdb, I keep getting that byte is 85 ‘U’. What has happened? Why don’t I see 0x55, or even the binary representation 110111?
Thanks for any help!
Use
p/x byteto look at it.gdbdefaults to printing decimal unless you tell it otherwise. You get the'U'because that’s also part of the default for printingchartype variables.The value stored in the variable is binary – it’s only how you’re looking at it that is confusing you, I think.
0x55,85, and'U'are all different ways to interpret the same data.