java bit manipulation

前端 未结 5 1012
日久生厌
日久生厌 2020-12-06 06:24
byte x = -1;
for(int i = 0; i < 8; i++)
{
    x = (byte) (x >>> 1);
    System.out.println(\"X: \" + x);
}

As I understand it, java sto

5条回答
  •  爱一瞬间的悲伤
    2020-12-06 06:47

    I'm not sure about this. But, my guess is that

    x >>> 1 
    

    gets promoted to a int from byte, because the literal "1" is an int. Then what you are observing makes sense.

提交回复
热议问题