当前位置: 代码迷 >> J2SE >> think in java4 中,<<<处理byte short char的解释 ,解决立即给分
  详细解决方案

think in java4 中,<<<处理byte short char的解释 ,解决立即给分

热度:316   发布时间:2016-04-24 12:48:43.0
think in java4 中,<<<处理byte short char的解释 在线等,解决立即给分
Shifts can be combined with the equal sign (<<= or >>= or >>>=). The lvalue is replaced by 
the lvalue shifted by the rvalue. There is a problem, however, with the unsigned right shift 
combined with assignment. If you use it with byte or short, you don’t get the correct results. 
Instead, these are promoted to int and right shifted, but then truncated as they are assigned
back into their variables, so you get -1 in those cases. The following example demonstrates 
this:  

红色部分怎么理解?谢谢

------解决方案--------------------
运算的时候提升为int,运算结束赋值的时候又把高位截掉了.
------解决方案--------------------
高位是 左边.. 右边是低位.
  相关解决方案