Several bit operations:
<: Shifts left (in the direction of the arrow). The removed high position is discarded, and the low position is zero.
>>: Shift right (the direction of the arrow), discard the removal of the low position, and add the high position to the symbol bit (if it is a positive number, add 0, if it is a negative number, Add 1 ).
>>>: The operation shifts right like the previous one, but the high position is zero no matter what the symbol bit is.
&: Perform and operate the two numbers by bit.
|: Perform or operate two values by bit.
^: Perform an exclusive or operation on two numbers by bit.
~ : Returns an inverse operation for each operand.
Bitwise operations are performed on the original code of the number. The original code of the integer is itself, and the original code of the negative number is the original code of the corresponding integer, and then + 1.
For example:
15 original code: 00000000 00000000 00000000 00001111
-15:
The original code of 15 is reversed:
11111111 11111111 11111111 11110000
Then + 1:
11111111 11111111 11111111 11110001.