C语言逻辑运算符
C语言如何实现一个a=11,使其二进制数第三位变成0放到b中,然后再从b中还原到a放到c中
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a = 11,b,c;
//a=00000000000000000000000000001011
// 00000000000000000000000000000100=(1<<2)
b = a |( 1 << 2);
printf("%d\n", b);//b=15
//b=00000000000000000000000000001111
// 11111111111111111111111111111011=(1<<2)
c = b & (~(1 << 2));
printf("%d\n", c);//a=11
system("pause");
}
输出示例