Friday, 23 August 2013

strange leading "f" when print out a char

strange leading "f" when print out a char

Hi guys, I wrote the following code:
union endian {
char a;
int b;
} test;
char c;
test.b = 0xaabbccdd;
c = (char)test.a;
printf("0x%x\n", c);
printf("0x%x\n", test.b);
printf("0x%x\n", test.a);
printf("0x%x\n", (char)test.a);
But the output is:
0xffffffdd
0xaabbccdd
0xffffffdd
0xffffffdd
I want to know why there is some leading 0xffffff before the char variable.

No comments:

Post a Comment