当我遇到一段看起来像这样的代码时,我在互联网上搜索 -
return c.getX() | c.getY() | c.getZ();
访问器方法返回整数,所以它让我思考, 如果你放一个&或者整数之间?
所以我亲自试了一下〜
for (int x = 0; x < 5; x++)
for (int z = 0; z < 5; z++) {
System.out.printf("%s | %s = %s\t%s & %s = %s\n", x, z, x | z, x, z, x & z);
}
这就是我得到的东西〜
0 | 0 = 0 0 & 0 = 0
0 | 1 = 1 0 & 1 = 0
0 | 2 = 2 0 & 2 = 0
0 | 3 = 3 0 & 3 = 0
0 | 4 = 4 0 & 4 = 0
1 | 0 = 1 1 & 0 = 0
1 | 1 = 1 1 & 1 = 1
1 | 2 = 3 1 & 2 = 0
1 | 3 = 3 1 & 3 = 1
1 | 4 = 5 1 & 4 = 0
2 | 0 = 2 2 & 0 = 0
2 | 1 = 3 2 & 1 = 0
2 | 2 = 2 2 & 2 = 2
2 | 3 = 3 2 & 3 = 2
2 | 4 = 6 2 & 4 = 0
3 | 0 = 3 3 & 0 = 0
3 | 1 = 3 3 & 1 = 1
3 | 2 = 3 3 & 2 = 2
3 | 3 = 3 3 & 3 = 3
3 | 4 = 7 3 & 4 = 0
4 | 0 = 4 4 & 0 = 0
4 | 1 = 5 4 & 1 = 0
4 | 2 = 6 4 & 2 = 0
4 | 3 = 7 4 & 3 = 0
4 | 4 = 4 4 & 4 = 4
我试图找到一种模式,但我无法得出任何结论。谁能告诉我这个模式和用法呢?