I am wondering why largest possible value of Int32 in .NET is 2147483647 but not 2147483648. Because 2³¹ = 2147483648.
Thank you
I am wondering why largest possible value of Int32 in .NET is 2147483647 but not 2147483648. Because 2³¹ = 2147483648.
Thank you
An Int32
is stored in 32 bits, not 31 bits, and half of its range is taken by negative numbers. Out of the remaining range, you lose one value to zero, leaving 2147483647 as the highest positive number.
The range for an Int32 is -2147483648 to 2147483647.
It also includes zero 0
in the positive range. Hence the range is 0
to 2147483647
and since zero has been considered in the positive side hence towards negative side from '-1' to -2147483648
.
So overall positive and negative side takes equal number of values.
The actual data of Int32 is stored in 31 bits, because regular Int32 should also hold negative numbers, 1 bit is used as a sign bit, 31 bits that remain are used as data. However, if you use unsigned Int32, then you will have a complete 32 bits of data in it.
It mean int
can have maximum 2147483648
positive values starting from 0
to 2147483647
, The int.Min
is -2,147,483,648 as it does not include the 0