有些时间 了 ,很多基础的 东西都忘了 ,留一些 笔记
占字节数1的有 [byte,boolean]
占字节数2的有 [short,char]
占字节数4的有 [int ,float(单精度)]
占 字节数8的有 [long(长整型),double(双精度)]
1个字节 8bit 2^(n-1) 占位
以int 为例 一个Int 范围为
2^(4*8-1)-1~-2^(4*8-1)
负数的移位 如果是 >> 的话 固定在 -1
<<效果类似 >>>没有边界的概念
例如
public void testMove3() {
int i = 2;
System.out.println(i >> 1);
System.out.println(i >> 3);
System.out.println(i<<31);
System.out.println(i<<30);
System.out.println(i<<32);
int j = -1;
System.out.println(j>>2);
System.out.println(j>>>1);
System.out.println(j>>>2);
int k = -3;
System.out.println(k>>2);
System.out.println(k>>>1);
System.out.println(k>>>2);
System.out.println(Integer.MAX_VALUE);
}
输出如下:
1
0
0
-2147483648
2
-1
2147483647
1073741823
-1
2147483646
1073741823
2147483647