I saw in MSDN documents that the maximum value of Int32
is 2,147,483,647
, hexadecimal 0x7FFFFFFF
.
I think, if it's Int32
it should store 32-bit integer values that finally should be 4,294,967,295
and hexadecimal 0xFFFFFFFF
.
My question is why Int32
stores 31-bit integer values?
The number 2,147,483,647 (or hexadecimal 7FFFFFFF16) is the maximum positive value for a 32-bit signed binary integer in computing. It is therefore the maximum value for variables declared as integers (e.g., as int ) in many programming languages.
The value of this constant is 2,147,483,647; that is, hexadecimal 0x7FFFFFFF.
A 32-bit signed integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). A 32-bit unsigned integer. It has a minimum value of 0 and a maximum value of 4,294,967,295 (inclusive).
In binary, 2147483647 is 01111111111111111111111111111111 and it's the biggest positive number that will fit in 32 bits when using the "two's complement" notation -- the way of representing numbers that allows for negative values.
It's because it's a signed integer. An unsigned 32-bit integer give you the value you expect.
Check out this MSDN page - http://msdn.microsoft.com/en-us/library/exx3b86w(v=vs.80).aspx
For a more in depth explanation on why this is check out the link in Jackson Popes answer related to Two's Complement number representation.
Also some further reading.
Because one bit is used to store the sign (Int32 can be less than zero).
http://en.wikipedia.org/wiki/Two%27s_complement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With