Why Java doesn't support <<< operator

前端 未结 4 668
醉梦人生
醉梦人生 2021-02-05 09:22

Why doesn\'t Java support the <<< (unsigned left shift) operator, but does support the >>> (unsigned right shift) operator?

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 10:00

    Why doesn't Java support the <<< (unsigned left shift) operator, but does support the >>> (unsigned right shift) operator?

    Because a (hypothetical) unsigned left shift operator would do exactly the same thing as the existing left shift operator.

    (Hint: multiplying a binary integer by 2 entails left shifting by 1 and making the rightmost bit zero whether the integer representation is signed or unsigned. Write some examples on a piece of paper and test it for yourself.)

提交回复
热议问题