0
How is byte b accepting +256 when range of byte is -128 to +128.
class ByteShift { public static void main(String args[]) { byte a = 64, b; int i; i = a << 2; b = (byte) (a << 2); System.out.println("Original value of a: " + a); System.out.println("i and b: " + i + " " + b); } }
4 Respostas
+ 5
Specialty of Java type cast - Java allows to store any 256 values as byte if you force it to. And you do by casting int 256 to byte.
+ 5
No. 257 will overflow and output 1.
0
The range of a byte has 256 possibilities. The range is -128 to 127. That's 128 negative numbers + 127 positive numbers + the number 0 = 256 possibilities.
0
So , can't b store 257 ?