I was trying to derive the Max and Min value of a
java int type.
Key Points :
1. int takes 4 bytes = 32 bits
2. its signed data type so first bit will be assigned as signed bit (if value = 0 then its positive integer else if 1 then negative integer)
3. number of bits used for values = 31
Max value = when all value bits are 1 and signed bit =0,
therefore Max Value = Sum = (1 x 2^0) + (1 x 2^1) + (1 x 2^2) + (1 x 2^3).........(1 x 2^31)
Applying Formula for Geometric Progression
Max Value = a((r^n) - 1) / (n-1) = ((2^31) - 1) / (2-1) = (2^31) - 1 = 2147483648 - 1 = 2147483647
and the Min value should be just the Negative of the Max value because the sole difference between the two cases is the change in the Sign Bit value and nothing else. One should be just the negative of another then why is the value Max value = 2,147,483,64
7 while Min value is -2,147,483,64
8 ?