#include <stdio.h>
#include <stdlib.h>
int main()
{
int and1=7;
int and2=1;
int or1=7;
int or2=1;
int not=7;
int xor1=7;
int xor2=1;
int andresult=and1&and2;
int orresult=or1&or2;
int notresutl=~not;
int xorresult=xor1^xor2;
printf("andresult %d\n",andresult);
printf("orresult %d\n",orresult);
printf("notresutl %d\n",notresutl);
printf("xorresult %d\n",xorresult);
int andresult2=andresult<<2;
int notresutl2=notresutl>>2;
printf("andresult2 %d\n",andresult2);
printf("notresutl2 %d\n",notresutl2);
return 0;
}
结果:
andresult 1
orresult 1
notresutl -8
xorresult 6
andresult2 4
notresutl2 -2
Process returned 0 (0x0) execution time : 0.156 s
Press any key to continue.
C里的与或非异或运算和java里的相同,C中没有直接输出二进制的函数或者通配符,
移位运算符: >>右移<<左移
右移一位,除以2,
左移一位,乘以2;