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

# MAX_VALUE

Ranch Hand
Posts: 60
• Number of slices to send:
Optional 'thank-you' note:
class Blue {
public static void main (String[] args) {
int i1 = (Integer.MAX_VALUE + 2);
int i2 = (Integer.MIN_VALUE + 1);
int i3 = (Integer.MIN_VALUE + 2);
int i4 = (Integer.MIN_VALUE + 3);
System.out.println((i1==i2)+","+(i1 ==i3)+","+(i1 ==i4));
}
}
thnk u,
basanti

Greenhorn
Posts: 26
• Number of slices to send:
Optional 'thank-you' note:
Integer.MAX_VALUE + 1 will result in Integer.MIN_VALUE.
So Integer.MAX_VALUE + 2 will result in Integer.MIN_VALUE + 1.
So i1==i2 is true.
That's why the result is true,false,false.

Ranch Hand
Posts: 60
• Number of slices to send:
Optional 'thank-you' note:
how did u arrive at the result. can u explain me?
basanti

Ranch Hand
Posts: 2120
• Number of slices to send:
Optional 'thank-you' note:
You need to study two's complement. It is the way Java represents Integral numbers.

Integer.MAX_VALUE = 0xEFFFFFFF
Integer.MIN_VALUE = 0x10000000

Ranch Hand
Posts: 60
• Number of slices to send:
Optional 'thank-you' note:
Thank you,
But is it calculated like this. pls correct me if am wrong.
max_value is represented in binary numbers and when u add 2 to it, convert 2 to binary numbers and then added to it?
where can i find the rules for binary addition.Are there rules for binary substraction and multiplication too?
thank again,
basanti

Ranch Hand
Posts: 279
• Number of slices to send:
Optional 'thank-you' note:
Jose, I think you made a mistake about the MAX, MIN values of int
Max is 0x7FFFFFFF and Min is 0x80000000
that's because the MSB is used for the sign.
1 + 0 = 1
1 + 1 = 0 and carry 1
so for 0x7FFFFFFF + 1 it changes all the Fs to 0s and the 7 to 8 and you get MIN_VALUE. If you add another 1 then it becomes 0x80000001 which is (MIN_VALUE + 1)

Ranch Hand
Posts: 60
• Number of slices to send:
Optional 'thank-you' note:
thanks everyone,
basanti

Jose Botella
Ranch Hand
Posts: 2120
• Number of slices to send:
Optional 'thank-you' note:
You are right Alfred.

 Don't get me started about those stupid light bulbs.