#include #include struct bitf unsign lmI unsigned bit 15: 1 i*bit buff, maino unsigned short x char buf[20] printf("这是一个位域结构体应用的例子n") for(;) printf("请输入一个整型数字(若想退出请输入O):") gets(buf); if(buf 0==o)break x(unsigned short)atoi(buf) bit buff(struct bitf*)&x printi("该数的十六进制是:%0xn",x) printi("该数在本机内表示的最高位是MBS:%dn” bit buff.->bit_15) printi("该数在本机内表示的最低位是LBS:%d", bit buff->bt0); printf("n")
#include #include struct bitf { unsigned bit_0:1; unsigned dummy:14; unsigned bit_15:1; }*bit_buff; main() { unsigned short x;char buf[20]; printf("这是一个位域结构体应用的例子\n"); for(;;) { printf("请输入一个整型数字(若想退出请输入 0):"); gets(buf); if(buf[0]=='0') break; x=(unsigned short)atoi(buf); bit_buff=(struct bitf*)&x; printf("该数的十六进制是:%0x\n",x); printf("该数在本机内表示的最高位是 MBS:%d\n",bit_buff->bit_15); printf("该数在本机内表示的最低位是 LBS:%d",bit_buff->bit_0); printf("\n"); } }