goback add

java中的移位运算

3259 点击·0 回帖
灯火互联
楼主


package com.wangshui.test;
public class Test1 {
    public static void main(String[] args) {
        /**
         * 8 2 16 32
         */
      
        //移位运算符对整数值i进行移位操作:
        //<<左移n位,右边用零填充,算数移位,相当于i*2^n。 >>右移n位,
        //左边用最高位填充(符号位),算术移位,相当于i/2^n。 >>>右移,左边用零填充,逻辑移位。
        System.out.println(4 << 1);// i*(2^n)
        System.out.println(4 >> 1);// i/(2^n)
        System.out.println(4 << 2);
        System.out.println(4 << 3);
    }
}


喜欢0 评分0