#include<stdio.h>
struct my
{
unsigned short a:4;
unsigned short b:5;
unsigned short c:7;
}test;
void main()
{
test.a=2;
test.b=3;
test.c=0;
int i=*((short *)&test);
printf("%d\n",i);
}
上述程序输出50,内存中是32(16进制),但把test.c=4时却输出2098,内存中832(16进制),却不是432。
我的理解是:内存中存储是a:4位,b:5位,c:7位,cba这样存储,这样432即是000,0100,00011,0010即为832(16进制)
也就是十进制的2098。