Hi there,
i have a question regarding two's complement in
java. i was solving this question the other day
*****************************************************
class EBH005 {
public static void main (
String[] s) {
byte b = 127; b <<= 2;
System.out.println(b);
}}
What is the result of attempting to compile and run the program?
a. Prints: -4
b. Prints: -3
c. Prints: -2
d. Prints: 0
e. Prints: 1
f. Prints: 127
g. Prints: 508
h. Run-time error
i. Compile-time error
j. None of the above
*************************************************************
the answer is a . Prints -4.
i cud understand the while conversion from 508 to byte , the left 3 bytes are left out. but with the remaining 1111 1100 how do u get to -4 .
i know there is the conversion from 0's to 1's and adding 1 , but i am little confused with that . can anyone kindly explain me the conversion and stuff.....
thx.
R0ss.