java位运算中的>> ; >>>


1. >>为右移运算,末位去除,整体向右移动一位,首位补上原首位数字。

  >若该数为正数(首位为0),则首位补0;
  >若该数为负数 (首位为1),则首位补1;

2. >>>为无符号右移运算,末位去除,整体向右移动一位,首位补上0;

  >无论该数的正负,其首位都补上0;

eg:

public class position_calculation {
public static void main(String[] args) {

   int b=-4;
   System.out.println(Integer.toBinaryString(b));
   System.out.println(Integer.toBinaryString(b>>1));
   System.out.println(b>>1);
   System.out.println(Integer.toBinaryString(b>>>1));
   System.out.println(b>>>1);

}
}

output:

11111111111111111111111111111100
11111111111111111111111111111110
-2
1111111111111111111111111111110
2147483646

原文地址:https://www.cnblogs.com/Auterman/p/13431306.html