c - Bit-field: Understanding how the following program works -
can you, please, explain me case:
struct registru { int bit3:4; }; struct registru bit={13}; printf("\n%d", bit.bit3);
why result -3 ?
we need careful while using bit-fields. declared variable int, in c default signed int.
if see binary value of 13, 1101. msb
taken sign value getting -3. if want take value 13 use below code:
struct registru { unsigned int bit3:4; }; void main() { struct registru bit={13}; printf("\n%d", bit.bit3); }
Comments
Post a Comment