#include<stdio.h>
#include<stdlib.h>
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");
}
}