File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Integer.MIN_VALUE???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Integer.MIN_VALUE????" Watch "Integer.MIN_VALUE????" New topic


Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
hi all,

Why does ......
give o/p as 80000000 should give ffffffff???

Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Let's see a sample:

Let's suppose that an integer insted of 32 bits has 4 bits. If it were unsigned it would be 2^3 = 8; but as it is unsigned we need to reserve a bit. That's to say 2^3-1 = 7 for positive and 2^3 = 8 for negative. Let's see why:

See we cannot represent the 8 because it would be using the bit sign. Now let's see the negatives.

Notice that negative numbers have the sign bit on. And that's why they can represent on more decimal number. Notice that the value of MIN_VALUE in this case is formed with all bits set to 0, but the sign bit. That is why the MIN_VALUE in interger is 80000000 and the one that you said is -1, because it has all the bits set to 1, that's to say ffffffff.

Remember that you obtain a negative number by means of negating the bits of the positive one and then adding one.

[ May 15, 2005: Message edited by: Edwin Dalorzo ]
[ May 15, 2005: Message edited by: Edwin Dalorzo ]
I agree. Here's the link:
subject: Integer.MIN_VALUE????
It's not a secret anymore!