1. Bitwise XOR or operation (^)
The arithmetic rules are: two numbers are converted to binary, then compared from high, if the same is 0, not the same is 1.
For example: 8^11.
8 to binary is 1000,11 to binary is 1011. The comparison from the high level is: 0011. Then the binary is converted to decimal, which is Integer.parseint ("0011", 2) = 3;
2. Bitwise AND operator (&)
Operation rules: Two numbers are converted to binary, then from the high start comparison, if the two number is 1 is 1, otherwise 0.
For example: 129&128.
129 conversion to binary is 10000001,128 to binary is 10000000. From a high level to get a comparison, get 10000000, that is, 128.
3. Bitwise OR operator (|)
Operation rules: Two numbers are converted to binary, and then from the high start comparison, two numbers as long as there is a 1 is 1, otherwise it is 0.
For example: 129|128.
129 conversion to binary is 10000001,128 to binary is 10000000. From a high level to get a comparison, get 10000001, that is, 129.
4. Bitwise non-operator (~)
Arithmetic rule: If the bit is 0, the result is 1, if the bit is 1, the result is 0.
For example: ~37
In Java, all data is represented in the form of a complement, and if there is no special description, the data type in Java is by default the length of the Int,int data type is 8 bits, one is four bytes, or 32 bytes, 32bit.
8 conversion to binary is 100101.
After the complement: 00000000 00000000 00000000 00100101
Reverse: 11111111 11111111 11111111 11011010
Because the high is 1, so the original code is negative, the complement of the negative is its absolute value of the original code to take the reverse, and add 1 at the end.
Therefore, we can restore the complement of this binary number: first, the end minus 1 is the inverse code: 11111111 11111111 11111111 11011001 Secondly, we will take the original code:
00000000 00000000 00000000 00100110, at this point the binary transcoding is 38
So ~37 =-38.
Java operator with (&), non (~), or (|), XOR (^)