>>和>>>区别

 public static void main(String[] args) {

      System.out.println(Integer.toBinaryString(-16));
      System.out.println(Integer.toBinaryString(-16>>2));
      System.out.println(Integer.toBinaryString(16));
      System.out.println(Integer.toBinaryString(16>>2));
      System.out.println(Integer.toBinaryString(-16));
      System.out.println(Integer.toBinaryString(-16>>>2));
      System.out.println(Integer.toBinaryString(16));
      System.out.println(Integer.toBinaryString(16>>>2));

      System.out.println(16 >>> 2);
      System.out.println(16 >> 2);
      System.out.println(-16 >>> 2);
      System.out.println(-16 >> 2);

      /*
      结论:
        >> :       
          负数右移用1补位
      
          正数右移用0补位
      
        >>>:
            无论正负,都用0补位
      */
  }
posted @ 2020-09-01 00:02  snail灬  阅读(303)  评论(0编辑  收藏  举报