再请教版主一个问题,有关位段的.我总是弄不清楚
struct bit
{ unsigned a_bit:2;
unsigned b_bit:2;
unsigned c_bit:1;
unsigned d_bit:1;
unsigned e_bit:2;
unsigned word:8;
};
main()
{
struct bit *p;
unsigned int modeword;
printf("Enter the mode word(HEX):");
scanf("%x",&modeword);
p=(struct bit *)&modeword;
printf("\n");
printf("a_bit:%d\n",p->a_bit);
printf("b_bit:%d\n",p->b_bit);
printf("c_bit:%d\n",p->c_bit);
printf("d_bit:%d\n",p->d_bit);
printf("e_bit:%d\n",p->e_bit);
}
例如输入96,则结果为
a_bit:2
b_bit:1
c_bit:1
d_bit:0
e_bit:2
能帮我解释为什么吗