根據我之前的學習知識, << 和 >> 運算的規則如下:
<<:左移運算:就是把當前這個二進制數向左移動多少位,低位空出的補零。高位移出的舍棄
>>:右移運算:就是把當前這個二進制數向右移動多少位,高位空出的來,原來最高位是什么,就補什么,低位移除的舍棄。
看下面的問題:
public class Demo { public static void main(String[] args) { int a = 123; int b = a >> 32; int c = a >> 64; System.out.println(a); System.out.println(b); System.out.println(c); } }
輸出結果:
123 123 123
看來這個結論並不是那么的正確, 根據試驗, 這個根據數據類型的不同,int --> 32位一個周期; long --> 64位一個周期。如此循環,而不僅僅是簡單的補位。