posted 22 years ago
As you said Byte.MAX_VALUE is 01111111. Now, when you multiply a number by 2, what happens is a shift left by one bit. So,
Byte.MAX_VALUE * 2
can be resolved to
01111111 << 1
which gives
11111110
whose value is -2.
To be sure, let's take the byte value 2 and make it negative (keyword: 2's complement):
2 is 00000010
to get -2 we invert all bits like this
11111101
and add 1, that is
11111110
As you can see we get the same value...
So Byte.MAX_VALUE * 2 is equal to -2