">>the arithmetic right shift operator, which represents the right shift with a symbol, uses the highest bit padding to fill the left empty space after the shift. The result of the right shift is: each shift, the first operand is removed by 2, and the number of moves is determined by the second operand.
According to the binary form to move all the numbers to the right of the towering digits, low-shifted out (discard), high position of the vacancy complement the sign, that is, positive 0, negative compensation ">>>"Unsigned Right shift operation, logical right SHIFT, means unsigned right shift, only bitwise operation, no arithmetic meaning, it fills the left vacancy with 0. In binary form, all numbers are shifted to the right by the corresponding number of digits, the low position is shifted out (discarded), and the upper slot is 0. For positive numbers, it is the same as a signed right shift, which is different for negative numbers. J>>>i and j/(int) (Math.pow (2, i)) The results are the same, where I and J are shaped. The arithmetic right shift does not change the symbol of the original number, while the logical right shift does not guarantee this. The shift operator is reduced to its right operand, and when the left operand is of type int, the right side is modulo 32, while the left side is a long type, and the right side is 64 modulo. Test Code 1: Public classTest { Public Static voidMain (string[] args) {System. out. println ("1, the following test;:"); intA =1, B =2; System. out. println (A >b); System. out. println ("\n2, the following test >>:"); System. out. println (">> 2 ="+ ( the>>2)); System. out. println ("\n3, the following test >>>:"); for(inti =0; I <Ten; i++) { for(intj =0; J < -; j = j +5) {System. out. println (J/(int) (Math.pow (2, i))); System. out. println (J >>>i); }}}} Test code 2: Public classTest { PublicTest () {System. out. println ("============= arithmetic right shift >> ==========="); intI=0xC0000000; System. out. println ("before shift: i="+i+" = "+integer.tobinarystring (i) +"(B)"); I=i>> -; System. out. println ("post-shift: I="+i+" = "+integer.tobinarystring (i) +"(B)"); System. out. println ("---------------------------------"); intj=0x0c000000; System. out. println ("before shift: j="+j+" = "+integer.tobinarystring (j) +"(B)"); J=j>> -; System. out. println ("post-shift: j="+j+" = "+integer.tobinarystring (j) +"(B)"); System. out. println ("\ n"); System. out. println ("============== Logical Right Shift >>> ============="); intm=0xC0000000; System. out. println ("before shift: m="+m+" = "+integer.tobinarystring (m) +"(B)"); M=m >>> -; System. out. println ("post-shift: M="+m+" = "+integer.tobinarystring (m) +"(B)"); System. out. println ("---------------------------------"); intn=0x0c000000; System. out. println ("before shift: n="+n+" = "+integer.tobinarystring (n) +"(B)"); N=n>> -; System. out. println ("post-shift: N="+n+" = "+integer.tobinarystring (n) +"(B)"); System. out. println ("\ n"); System. out. println ("the model =============== of ============== shift symbol"); intA=0xcc000000; System. out. println ("before shift: A="+a+" = "+integer.tobinarystring (a) +"(B)"); System. out. println ("arithmetic right shift 32:a="+ (a>> +)+" = "+integer.tobinarystring (a>> +)+"(B)"); System. out. println ("logical Right Shift 32:a="+ (a>>> +)+" = "+integer.tobinarystring (a>>> +)+"(B)"); } Public Static voidMain (string[] args) {NewTest (); }} Run Result:============= arithmetic right shift >> ===========before shift: I= -1073741824=11000000000000000000000000000000(B) After displacement: I= -4=11111111111111111111111111111100(B)---------------------------------before shift: J=201326592=1100000000000000000000000000(B) post-shift: J= A=1100(B)============== logical Right Shift >>> =============before shift: M= -1073741824=11000000000000000000000000000000(B) post-shift: M= A=1100(B)---------------------------------before shift: N=201326592=1100000000000000000000000000(B) after displacement: n= A=1100(B)
">>" and ">>>" Java