Multiplication of Integer.MAX_VALUE in Java -
this question has answer here:
i playing around in java. wrote small program:
public class maxvalue{ public static void main(string[] args){ int = integer.max_value; for(int j = 1; j<=10;j++){ system.out.println(i*j); } } }
the output follows:
2147483647
-2
2147483645
-4
2147483643
-6
2147483641
-8
2147483639
-10
now got surprised. not know how explain output. know can use long instead handling values more max limit of integer. interested know how java calculates this?
we need analize binary content of result:
integer.max_value * 1 = 0x7fffffff decimal 2147483647
integer.max_value * 2 = 0xfffffffe -2
integer.max_value * 3 = 0x17ffffffd 33 bits, after truncation 0x7ffffffd 2147483645
and on...
Comments
Post a Comment