定义
#include<stdio.h>
int main()
{
int a=0;
printf("%d\n",~a);
return 0;
}
a=0;00000000000000000000000000000000
~a:11111111111111111111111111111111-补码
反码:11111111111111111111111111111110
原码:10000000000000000000000000000001
原码就是-1
引入
1.将1011变为1111
11:00000000000000000000000000001011
| :00000000000000000000000000000100
需要或上一个0100,0100可以由0001<<2得到
#include<stdio.h>
int main()
{
int a=11;
//00000000000000000000000000001011
a=a|(1<<2);
printf("%d\n",a);
return 0;
}
取反.
将1111变回1011
11:00000000000000000000000000001111
& :11111111111111111111111111111011
需要与上一个1011,1011可以由0100取反后得到,0100可从0001<<2得到
#include<stdio.h>
int main()
{
int a=11;
//00000000000000000000000000001011
a&(~(1<<2));
printf("%d\n",a);
return 0;
}