I was searching around on the internet when I came across a snippet of code that looked like this -
return c.getX() | c.getY() | c.getZ();
The accessor methods return integers, so it got me thinking, What does it mean if you put an & or | between integers?
So I tried it out for myself~
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);
}
Here's what I got~
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
I was trying to find a pattern, but I couldn't come to any conclusion. Can anyone tell me the pattern and use of this?