Left bit shifting 255 (as a byte)

前端 未结 7 702
臣服心动
臣服心动 2020-12-01 18:41

Can anyone explain why the following doesn\'t compile?

byte b = 255 << 1

The error:

Constant value \'510\' can

相关标签:
7条回答
  • 2020-12-01 19:00

    You are shifting 255 by 1 bit, then trying to assign it to a byte. 255 << 1 is 510, and 510 won't fit in to a byte.

    0 讨论(0)
提交回复
热议问题