If the values of the Char,byte or short type are shifted, they will be converted to the int type before the shift is made.
and the resulting result is also an int type.
If the value of long is processed, the result is long.
If this right-shift (>>>=) operation is performed on a byte or short value, the resulting result may be incorrect, and they will be converted to the INT type.
It is then truncated and assigned to the original type.
Public classTest {/** * @paramargs*/ Public Static voidMain (string[] args) {intI=-1; System.out.println (integer.tobinarystring (i)); I>>>=10; System.out.println (integer.tobinarystring (i)); byteB=-1;//11111111System.out.println (integer.tobinarystring (b));//Call an integer tobinarystring (int x) 32 1b>>>=10;//after the shift is 1111111111111111111111, because B is a byte type, so b= 11111111, or-1 valueSystem.out.println (integer.tobinarystring (b));//also output 32 x 1B=-1; System.out.println (integer.tobinarystring (b)); System.out.println (integer.tobinarystring (b>>>10));//no assignment after shift, direct output, 22 x 1 } }
11111111111111111111111111111111
1111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
1111111111111111111111
Problems with the Java shift operator attention