Why is Int32's maximum value 0x7FFFFFFF?

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


Int32 and Int64 are both signed so they can handle integer values from -capacity/2 to (capacity/2)-1 (for zero) that is why the max value isn't the one you expected. But you can get what you want by using an unsigned int to have only positive numbers.

Tags:

C#

Types

Int32