/**
* @author ThompsonGuo
* @date 8/23 22:11
*/
//正数的左移或者右移操作都是空位补0;
//而负数的左移是空位补0,符号位不变,若所移动位数超出符号位则左移结果为原数,右移是空位补1。
//负数的无符号右移<<<与右移相同
public class byteMove {
public static void main(String[] args) {
int i = 1; (0001)
int j = -1; (1111)
int a1 = i << 1; (0010)2
int a2 = i >> 1; (0000)0
int b1 = j << 2; (1100)-4
int b2 = j >> 2; (1111)-1
System.out.println("i左移一位是:" + a1);
System.out.println("i右移一位是:" + a2);
System.out.println("j左移2位是:" + b1);
System.out.println("j右移2位是:" + b2);
}
}
i左移一位是:2
i右移一位是:0
j左移2位是:-4
j右移2位是:-1