From: http://darrendu.iteye.com/blog/773072
"<", ">>", And" >>> "in Java are operators for moving left, signed right, and unsigned right. The offset operator only operates on the int value. If it is not an int value, the compiler reports an error. In Java, the length of an int is always 32 bits, that is, 4 bytes.
(1) left moving OPERATOR:
The number of operations is moved to the left. The number of BITs to be moved is specified by the left operand,The low position is automatically set to zero (0 ).
(2) right moving OPERATOR:
In turn, the operand is moved to the right, and the number of bits to be moved is also specified by the right operand.Note: In the face of numbers with positive and negative numbers, the symbol extension is used. If the original value is positive, 0 is added to the high value. If the original value is negative, 1 is added to the high value.
(3) right shift operator without plus or minus signs (>>> ):
Supplement with 0, meaning,Both positive and negative signs are filled with 0 at a high level.
Below I want to parse these three operators in detail:
1. Preparation knowledge
Able to skillfully convert Positive and Negative binary codes;
Conversion principle:Anti-increment "1"
If you have any questions, seeArticleContent in "Java Basic Knowledge series 3"
2: Use instances to describe analysis operations.
Public classTest {
Public static voidMain (string [] ARGs ){
IntM =-7;
System.Out. Println ("M's binary code is:" + integer.Tobinarystring(M ));
System.Out. The binary code of println ("m> 2 is:" + integer.Tobinarystring(M> 2 ));
System.Out. Println ("(M> 2) =" + (M> 2 ));
System.Out. Println ("m <2 binary code is:" + integer.Tobinarystring(M <2 ));
System.Out. Println ("(m <2) =:" + (M <2 ));
System.Out. Println ("m >>> the binary code of 24 is:" + integer.Tobinarystring(M> 24 ));
System.Out. Println ("m >>> 24:" + (M >>> 24 ));
}
}
Execution result:
M binary code: 11111111111111111111111111111001
The binary code of M> 2 is: 11111111111111111111111111111110
(M> 2) =-2
M <2 binary code is: 11111111111111111111111111100100
(M <2) =:-28
M >>> the binary code of 24 is: 11111111
M >>> 24: 255