Left bit shifting 255 (as a byte)

前端 未结 7 735
臣服心动
臣服心动 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 18:58

    And since << has a higher precedence than & you can save the brackets:

    byte b = 255 << 1 & 0xff;
    

提交回复
热议问题