Bitwise operators in Java:
>>: means right shift. If the number is positive, the high bits are filled with 0. If it is a negative number, then Fill the high bits with 1;
>>>: Indicates unsigned right shift, also called logical right shift, that is, if the number is positive, the high bits will be filled with 0, and if the number is negative, the right The high bit after the shift is also filled with 0.
The expression is:
result = exp1 >> exp2; result = exp2 >>> exp2;
means moving the number exp1 to the right by exp2 bits.
For example: The binary number of
res = 20 >> 2;
20 is 0001 0100. After shifting right by 2 bits, it is 0000 0101. The result is res = 5; the binary number of
res = -20 >> 2;
-20 Add 1 to the complement of its positive number, that is, 1110 1011. After shifting right by 2 bits, it is 1111 1100. The result is res = -6;
And for the >>> symbol:
res = 20 >>> 2;
The result is the same as >
##Supplement:
<< is the left shift operator corresponding to >>, which means moving exp1 to the left by exp2 bits and filling in the low bit with 0. In fact, moving n bits to the left is equivalent to multiplying by 2^n.
There is no <<< operator for left shift! Recommended tutorial:Java tutorial
The above is the detailed content of The difference between >>> and >> in java. For more information, please follow other related articles on the PHP Chinese website!