移位操作符 << >> >>>
按位操作符只可用于int类型,其它类型都会转化位int类型在操作,并且只有数值右端的低5位才右用(因为2^5=32)
<< 左移位操作符,低位补零
>> 右移位操作符,有符号数高位补1,无符号数高位补0
>> java专用右移位操作符;无任正负,都在高位插入0(linux 下负数用>>>在高位补1)
//: object/Shifting.java package object; import java.util.*; import static net.util.Print.*; public class Shifting{ public static void main(String[] args){ int n1 =-4; print("n1<<2 = "+Integer.toBinaryString(n1<<2)); print("n1<<2 = "+Integer.toBinaryString(n1>>2)); print("n1<<2 = "+Integer.toBinaryString(n1>>>2)); print("n1<<2 = "+(n1>>>2)); } }/* output: n1<<2 = 11111111111111111111111111110000 n1<<2 = 11111111111111111111111111111111 n1<<2 = 111111111111111111111111111111 n1<<2 = 1073741823 *///~