The complement of the original code of the positive number is the same. Let's talk about the complement of the original code of the negative number. Take -1 as an example.
Original code 100000001
Inverse code 1111111110
Complement 1111111111
The java examples are calculated in two's complement.
2+(-1)=00000010 + 11111111=00000001 is 1
bit manipulation
a&b If both a and b are 1, the result is equal to 1, otherwise it is equal to 0
a|b If either a or b is 1, the result is equal to 1, otherwise it is equal to 0
>> n The sign is unchanged and the other bits are shifted right by n. The high bits are filled with 0. -5>>1 10000101 >> 10000010
>>>n The sign bit is then shifted to the right by n. The high bits are filled with 0. -5>>>1 10000101 >>>01000010
Of course, int in java is 32-bit, and the 8-bit alternative is used above, and the principle is the same.