详解
首先举一个样例来说明不是循环移位:
假设上面的程序改为
i = 3L << 63
程序的结果仍然为
1000000000000000000000000000000000000000000000000000000000000000
那么就说明Java中的移位运算不是循环的。
那对上面的问题又怎么解释呢?
在JLS(Java Language Specific 15.19)中有例如以下解释:If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (§15.22.1) with the mask value 0x1f (0b11111). The shift distance actually used is therefore always in the range 0 to 31, inclusive.
If the promoted type of the left-hand operand is long, then only the six lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (§15.22.1) with the mask value 0x3f (0b111111). T