zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    枚举
    IOS uitableview代理方法
    IOS图片拉伸模式
    IOS单例的设计模式
    圆角属性
    IOS 随机数
    IOS正则表达式
    添加 分类 自动适配图片
    用grep查找文件内容
    Openscada远程配置
  • 原文地址:https://www.cnblogs.com/Auterman/p/13431306.html
Copyright © 2011-2022 走看看