• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Integer.MIN_VALUE????

 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,

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

thanx
amit
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic