Click to enter _ more _java thousand ask
1, >, >>, >>> what is the difference
See Java operators here: What are the operators of Java
Understanding Java Operator Precedence See here: What is the precedence of Java operators
">" belongs to relational operators, while ">>", ">>>" bitwise operators look at their respective meanings:
Operators >
The relational operator, which represents greater than.
such as: if (a>b) ... The result is a Boolean type.
Operators >>
A bitwise operator that represents the right shift. << represents a left shift.
j<< i. Equals num divided by 2 n power, j/(int) (Math.pow (2, i)).
such as: int i=15; The result of the I>>2 is 3, and the removed part will be discarded.
The transition to binary may be better understood, 0 0000 1111 (15) The result of moving the 2-bit right is 0 0000 0011 (3).
Understanding binary operations See here: How binary is doing bit arithmetic
- Operators >>>
A bitwise operator that represents the unsigned right shift.
Similar to >>, but ignores the sign bit while moving, and the empty space is padded with 0.
The unsigned Right shift operator >>> is only meaningful (and negative) for 32-bit and 64-bit values, and the rest is consistent with >>.
Instance:
System. out. println("1, the following test;:");int a = the, B =2, C =- the;System. out. println(A > B);System. out. println("\n2, the following test >>:");System. out. println(A +"/(int) (Math.pow (2,"+ B +"))) = "+ (A/(int) (Math. Pow(2, b))));System. out. println(A +">>"+ B +" = "+ (a >> b));System. out. println(C +">>"+ B +" = "+ (c >> b));System. out. println("\N3, the following test >>>:");System. out. println(A +">>>"+ B +" = "+ (a >>> b));System. out. println(C +">>>"+ B +" = "+ (c >>> b));
The results of the implementation are as follows:
1, the following test;:
True
2, the following test >>:
(int) (Math.pow (2, 2)) = 3
>> 2 = 3
-15 >> 2 =-4
3, the following test >>>:
>>> 2 = 3
-15 >>> 2 = 1073741820
Java thousand asked _03 Basic grammar (013) _>, >>, >>> what is the difference