The question is
class Blue {
public static void main (String[] args) {
byte b1 = (byte)(2 * Byte.MAX_VALUE);
byte b2 = -1;
byte b3 = -2;
byte b4 = -3;
System.out.println((b1==b2)+","+(b1==b3)+","+(b1==b4));
}
}
And the answer is:
When Byte.MAX_VALUE is multiplied by two, the result is a byte with the most significant seven bits set to one and the least significant bit set to zero. The two's compliment representation of negative two is the same.
Byte.max is 128, multiplied by two is 256, and that is an int, which when typecasted to byte should give a value of zero. Any explanation please?