File APIs for Java Developers Manipulate DOC, XLS, PPT, PDF and many others from your application. http://aspose.com/file-tools
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login

# Integer.MIN_VALUE????

Amit Das
Ranch Hand

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

Why does ......
System.out.print(Integer.toHexString(Integer.MIN_VALUE));
give o/p as 80000000 ...it should give ffffffff???

thanx
amit
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: http://aspose.com/file-tools

subject: Integer.MIN_VALUE????