void main()
{
unsigned int flag=181;//10110101
//设置第四位:置1:(写操作)
flag|=(0x1<<3);
printf("%u\n",flag);
//清除某位:清零(写操作)
flag&=(~(0x1<<3));
printf("%u\n",flag);
//判断某位是否为1(读操作)
printf("%u\n",flag&(0x1<<3));
//判断某位是否为1(读操作)也可以这样写
printf("%u\n",(flag>>3)&0x1);
system("pause");
}
void main()
{
unsigned int flag=181;//10110101
//设置第三位到第五位为1:
flag|=(0x07<<3);
printf("%u\n",flag);
//设置第三位到第五位为0:清除
flag&=(~(0x7<<3));
printf("%u\n",flag);
//判断第三位到第五位的值是否都为1:
printf("%u\n",flag&(0x07<<3));
system("pause");
}