Bit operators in C did not learn, so it is new knowledge, as for the use, I am not very clear, first to see it.
&:
The two number of participating operations, if the value of the corresponding bits number is 1, then the result value is 1, otherwise 0, similar to "with", for example:
System.out.println(3 & 5);//结果为1运算过程如下: 00000011(3) 00000101(5) &\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 00000001(1)
|
As long as there is a 1 in the corresponding bit of the two number of participating operations, the result is 1, similar to "or", for example:
System.out.println(3 | 5);//结果为7运算过程如下: 00000011(3) 00000101(5) |\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 00000111(7)
^:
The two numbers participating in the operation have the same corresponding bit and the result is 0, otherwise the result is 1, similar to XOR, for example:
System.out.println(3 ^ 5);//结果为6运算过程如下: 00000011(3) 00000101(5) ^\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 00000110(6)
~
Change each bits ' 1 ' to ' 0 ', change ' 0 ' to ' 1 ', similar to reverse, for example:
System.out.println(~ 5);//结果为-6运算过程如下: 00000101(5) ~\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 11111010(-6)
In fact, there are ' << ', ' >> ', ' >>> ' three bitwise operators, but it's a bit more difficult, so let's talk about it next time.
Java Learning Journey-4