学习使用按位或(|)
按二进制位,有一位为1则结果为1
#include <stdio.h>
#include <stdlib.h>
int main(){
int a = 10; //1010
int b;
b = a | 11; //1011
printf("%d\n", b); //11
b |= 2; //0010
printf("%d\n", b); //11
system("pause");
return 0;
}
//学习使用按位异或(^)
#include <stdio.h>
#include <stdlib.h>
int main(){
int a = 10; //1010
int b;
b = a ^ 11; //1011
printf("%d\n", b); //0001->1
b ^= 2; //0011
printf("%d\n", b); //3
system("pause");
return 0;
}