#include<stdio.h>
void bit_set(unsigned char *p, unsigned char position, int flag)
{
if(flag==1)
{
//11110000
//00010000
*p|=(1<<(position-1));
}
if(flag==0)
{
//11110000
//11101111
*p&=~(1<<(position-1));
}
}
int main()
{
unsigned char ch=13;
printf("%d\n",ch);
bit_set(&ch,2,1);
printf("%d\n",ch);
return 0;
}
对指定位进行置0或置1操作
最新推荐文章于 2023-06-25 15:39:54 发布