This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes one question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "one question" Watch "one question" New topic
Author

one question

dpy learn
Greenhorn

Joined: Nov 11, 2005
Posts: 4
why 1111 1000 0000 0000 0000 0000 0000 0000=-134217728
Anatol Bollinger
Greenhorn

Joined: Nov 10, 2005
Posts: 11
I asked myself this question a couple of days ago. The method used is the two's complement: Wikipedia: Two's complement

Cheers, Anatol
dpy learn
Greenhorn

Joined: Nov 11, 2005
Posts: 4
oh,i cannot see the Wikipedia: Two's complement
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

An int is 32 bits. The first (left most) bit indicates the sign: 1 for negative, 0 for positive.
If the left most bit is 1, you can determine the number by changing each 1 to 0 and 0 to 1, then adding 1.

So:
1111 1000 0000 0000 0000 0000 0000 0000 = -134217728

Flip bits:
0000 0111 1111 1111 1111 1111 1111 1111 = 134217727

Add 1: 134217728.

And then add the - sign.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
jQuery in Action, 2nd edition
 
subject: one question