Based on the fact that a byte type in java is a signed 8 bit two\'s complement integer, why doesn\'t the second way of declaring a byte work?
byte
b
0b10000000 is an int literal (= 0b00000000000000000000000010000000) which equals to +128. byte holds 8 bits and cannot represent +128. However, you can achieve this as follows:
0b10000000
int
= 0b00000000000000000000000010000000
+128
byte notok = (byte) 0b10000000;