//按位取反操作符 ~
int main()
{
//把二进制数第五位改成1
int a = 13; //00000000 00000000 00000000 00001101 ,13
a = a | (1 << 4); //00000000 00000000 00000000 00010000 ,1
printf("a = %d\n", a); //00000000 00000000 00000000 00011101 ,29
//把二进制数第五位改成0
int b = 0;
b = a & ~(1 << 4); //00000000 00000000 00000000 00001101 ,13
printf("b = %d\n", b); //00000000 00000000 00000000 00010000 ,1
//11111111 11111111 11111111 11101111 , 这是按位取反后的
//00000000 00000000 00000000 00001101 , 13
return 0;
}
记录每日学习13
最新推荐文章于 2024-08-28 14:35:43 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)