Given: 60 = 0011 1100; 195 = 1100 0011; RR #10 says that the complement (~) operator causes the bit pattern 0011 1100 to become 1100 0011. I figured, in the following code, b should be printed out as being 195, but b's result is actually -60. How should I be coding, below, to prove the question correct? Is a byte in Java the same thing as an eight-bit bit pattern? (ie xxxx xxxx) Is there a way to explicitly input and output a number's bit pattern? In the code, I am correctly using the ~ operator, aren't I?
I'm going through the ones in which I take the answers for granted, and coding them to beat the ideas home. Give a holler if these type of posts would better suit the "beginner" forum.
Joined: Aug 30, 2000
Hi Steven, Because 'b' is declared as an <code>int</code>, all the empty bits are being filled with the left-most bit value of '1' which signifies a negative in two's-complement arithmetic. To see the bit patterns, you can use <code>Integer.toBinaryString(value)</code> Might be better to post these in the Certification Study forum; your questions could prove useful to others. I'll transfer this one over. Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform [This message has been edited by Jane Griscti (edited May 29, 2001).]