Shift operators including >>>
operate on int
s. The value of b
, which is -1
because byte
is signed, is promoted to int
before the shift. That is why you see the results that you see.
The reason why 255
is re-interpreted as -1
is that 255 has all its eight bits set to one. When you assign that to a signed 8-bit type of byte
, it is interpreted as -1
following two's complement rules.