Signed left shift behaviour

喜欢而已 提交于 2019-12-01 13:48:31

The value of n << s is n left-shifted s bit positions; this is equivalent (even if overflow occurs) to multiplication by two to the power s.

And it's true: this is exactly the result you'd get if you multiplied -0x55555555 by two to the power of s, due to overflow. In particular, 0x55555555 has alternating 0s and 1s, so you're shifting alternating 0s and 1s into the sign bit, so the sign is flipping every time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!