>>>>运算符允许将int和long视为32位和64位无符号整数类型,这在Java语言中是缺失的。
当你移动不代表数值的东西时,这是非常有用的。例如,您可以使用32位整数表示黑白位图图像,其中每个int在屏幕上编码32像素。如果你需要向右滚动图像,你更喜欢int左边的位成为零,这样你可以很容易地把相邻的int的位:
int shiftBy = 3;
int[] imageRow = ...
int shiftCarry = 0;
// The last shiftBy bits are set to 1, the remaining ones are zero
int mask = (1 << shiftBy)-1;
for (int i = 0 ; i != imageRow.length ; i++) {
// Cut out the shiftBits bits on the right
int nextCarry = imageRow & mask;
// Do the shift, and move in the carry into the freed upper bits
imageRow[i] = (imageRow[i] >>> shiftBy) | (carry << (32-shiftBy));
// Prepare the carry for the next iteration of the loop
carry = nextCarry;
}
上面的代码不注意上面三位的内容,因为>>>运算符使它们
没有相应的<