c - strange leading "f" when print out a char -
hi guys, wrote 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 output is:
0xffffffdd 0xaabbccdd 0xffffffdd 0xffffffdd
i want know why there leading 0xffffff
before char variable.
%x
interprets argument unsigned int
. integers passed variadic function promoted int
, signed char
values being promoted signed int
s using sign extension, interpreted unsigned int
%x
.
you can work around casting unsigned char
or uint8_t
.
Comments
Post a Comment