This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
byte b1 = -5; int i = 0xff; byte b2 = (byte) (b1 ^ 1); f 1011 f 1111 _______^ 0 0100 b2++; 4 + 1 ^ is or-exclusive. Only yields true if its two entries are distinct. That is 1^1 or 0^0 yield 0, but 1^0 or 0^1 yields 1 Read Cat and Mouse Games with bits for more.
Originally posted by sun par: I also get -5 and I am confused
Sunita If you replace byte b2 = (byte) (b1 ^ 1); with byte b2 = (byte) (b1 ^ i); the result will be 5. Perhaps there was a typo in the test question? [ January 10, 2003: Message edited by: John Paverd ]