OPERAND1 ShiftOperator Operand2中与负操作数的Java按位移位运算符
换档规则
如果两个操作数为负,不要忘记来计算,因为负的2的补使用2的补码将整数存储在内存中
掩码操作数2为0 x1F的
Right shift 81814621>>-12 = 78 81814621>>>-12 = 78 OK!! Right shift (Operand1 is NEGATIVE) -81814621>>-12 = -79 -81814621>>>-12 = 4017 Why different?
Left shift
21<<-12 = 22020096
-21<<-12 = -22020096
Unlike Right shift no matter Operand1 is Positive/Negative
only sign get changed instead value
感谢您的支持!现在我对它有更好的想法...... :)
你了解'>>'和'>>>'的区别吗? –
任何人都可以解释它-81814621 >> - 12 = -79 AND -81814621 >>> - 12 = 4017它如何得到计算而不是理论解释... –
它完全按照JLS中所述进行计算。不是根据你上面描述的。 – EJP