• Post Reply Bookmark Topic Watch Topic
  • New Topic

Value of Integer.MIN_VALUE & -Integer.MIN_VALUE  RSS feed

 
sachin jauhari
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the Value of Integer.MIN_VALUE & -Integer.MIN_VALUE are same.
 
Steve Simon Joseph Fernandez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting question

From inside Sun's code, the declaration for Integer.MIN_VALUE is:



Which is, 4 bytes, and the left-most bit as 1. Now, -1 is 0xffffffff (all 1's) When you multiply both, an overflow occurs; only the first partial result is retained. And that is MIN_VALUE itself

_steve.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!