逻辑运算

逻辑运算

1
2
3
4
5
6
7
8
9
private static void test7() {
// 逻辑运算
int a = 2;
int b = 3;
System.out.println(a + "," + b + "与运算结果:" + (a & b));
System.out.println(a + "," + b + "或运算结果:" + (a | b));
System.out.println(a + "," + b + "异或运算结果:" + (a ^ b));
System.out.println(a + "的非运算结果:" + (~a));
}

结果:

1
2
3
4
2,3与运算结果:2
2,3或运算结果:3
2,3异或运算结果:1
2的非运算结果:-3