#include #include #include /* 有符号 结构体1*/struct bits{ int b1:5; /* 由于是int型,最大设置32位。由于int型是有符号整形, 所以这里5位为有符号类型。 11111 -1 10000 -16 01111 15 00000 0 */ int :2; int b2:2; /* 11 -1 10 -2 01 1 00 0 */ int b3:1; /* 1 -1 0 0 */ };/* 无符号 结构体2*/struct bits{ unsigned int b1:5; unsigned int :2; unsigned int b2:2; unsigned int b3:1;};int main(){ struct bits b;// int a = 0b1111111111111111; int a = 0b0100110101000101; memcpy(&b, &a, sizeof(b));// memcpy(&b, "EM", sizeof(b)); printf("0x%X\n", b); printf("b.b1 = %d\n", b.b1); printf("b.b2 = %d\n", b.b2); printf("b.b3 = %d\n", b.b3);}/*int a = 0b0100110101000101;0x4D45b.b1 = 5b.b2 = -2b.b3 = 0int a = 0b1111111111111111;0xFFFFb.b1 = -1b.b2 = -1b.b3 = -1int a = 0b0100110101000101;0x4D45b.b1 = 5b.b2 = 2b.b3 = 0int a = 0b1111111111111111;0xFFFFb.b1 = 31b.b2 = 3b.b3 = 1*/