Consider the following Java code:
byte a = -64;
System.out.println(a << 1);
The output of this code is -128
I tried as follows to figure out why this is the output:
64 = 0 1000000 (the MSB is the sign bit)
-64= 1 1000000 (Tow's complement format)
Expected output after shifting: 1 0000000 (This is equal to 0, because the MSB is just a sign bit)
Please anyone explain what I am missing.