Shift
In Java there are binary moves in the left (<<) and right Shift (>>)
Where right shift is also divided into signed right shift (>>) and unsigned Right shift (>>>)
1. Signed right shift: Move the binary to the right if the original sign bit is 0 then the new sign bit also uses 0 otherwise 1;
2. Unsigned right shift: Move the binary to the right regardless of the original sign bit is 0 or 1 will be used 0 complement;
Positive negative number conversion
As an example:
The binary of 3 is represented by a single byte
0000 0011
Normal a negative number of the method is: its positive number is reversed by a bitwise AND plus 1
0000 0011
Reverse: 1111 1100
Plus one: 1111 1101 (This is the binary representation of 3)
But there are quicker ways to convert:
Binary from left to right see the last 1 unchanged, all the rest take the reverse
0000 0011 (3)
1111 1101 (-3)
Post-Replenishment Knowledge:
When a byte type negative number is converted to an integer, the other 24 bits are filled with one, and the positive number is filled with zeros. If you want negative numbers to be filled with zero, you have to use this negative number with 0xFF and then convert to int type OK.
Shift operators in Java and positive negative numbers conversions