File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Mock Exam Errata and the fly likes RR #10 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "RR #10" Watch "RR #10" New topic

RR #10

Steven YaegerII
Ranch Hand

Joined: May 31, 2000
Posts: 182
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.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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).]

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
I agree. Here's the link:
subject: RR #10
It's not a secret anymore!