>>: Signed right shift. Positive numbers are shifted to the right and the high bits are filled with 0, and negative numbers are shifted to the right and the high bits are filled with 1s. For example:
4 >> 1, the result is 2; -4 >> 1, the result is -2. -2 >> 1, the result is -1.
>>>: Unsigned right shift. Regardless of whether it is a positive or negative number, the high bits are always filled with 0. (Recommended learning: java course)
For positive numbers, there is no difference between >> and >>>.
For negative numbers, -2 >>> 1, the result is 2147483647 (Integer.MAX_VALUE), -1 >>> 1, the result is 2147483647 (Integer.MAX_VALUE) ).
The following code can determine whether the signs of two numbers are equal
return ((a >> 31) ^ (b >> 31)) == 0;
For example:
-12 >> 3 is a signed right shift of 3 digits. The result is: 1111 1111 1111 1111 1111 1111 1111 1110. The decimal system is: -2;
-12 > Zero is: 0001 1111 1111 1111 1111 1111 1111 1110, in decimal: 536870910.
The above is the detailed content of The difference between java >>> and >>. For more information, please follow other related articles on the PHP Chinese website!