>Indicates greater than , such as: if(a>b)...The result is boolean type
>> means signed right shift , such as: int i=15; The result of i>>2 is 3, and the moved part will be discarded.
It may be easier to understand by converting it to binary form. The result of 0000 1111(15) shifted right by 2 bits is 0000 0011(3), and the result of 0001 1010(18) shifted right by 3 bits is 0000 0011(3).
>>>Unsigned right shift :
Move all numbers to the right by the corresponding number of digits in binary form, shift out the low bits (discard), and fill in the empty bits in the high bits with zeros. The same as signed right shift for positive numbers, but different for negative numbers.
Other structures are similar to >>.
The test code is as follows:
public class Test{ public static void main(String[] args){ System.out.println("1. The following test>:"); int a = 1, b = 2; System.out.println(a > b) ; System.out.println("/n2, following test >>:"); System.out.println("15 >> 2 = " + (15 >> 2)); System.out.println("/n3, the following tests >>>:"); for (int i = 0; i < 10; i++){ for (int j = 0; j < 500; j = j + 5) { System.out.println(j / (int) (Math.pow(2, i))); System.out.println(j >>> i); } } } }
Other bitwise operators in JAVA:
~ Bitwise NOT (NOT) (unary operation)
& bitwise AND
| Bitwise OR (OR)
^ Bitwise XOR (XOR)
>>Move right
>>> Shift right, filling the empty bits on the left with 0s
<< shift left
&= bitwise AND assignment
|= Bitwise OR assignment
^= Bitwise XOR assignment
>>= right shift assignment
>>>= Right shift assignment, the empty bits on the left are filled with 0
<<= left shift assignment