Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Int32's maximum value 0x7FFFFFFF?

Tags:

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?

like image 606
Afshin Mehrabani Avatar asked Nov 05 '12 10:11

Afshin Mehrabani


People also ask

Why is 2,147,483,647 The maximum number?

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.

What is the value of 0x7FFFFFFF?

The value of this constant is 2,147,483,647; that is, hexadecimal 0x7FFFFFFF.

What is the max value of 32-bit integer?

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).

How high can you count with 32 bits?

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.


2 Answers

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.

like image 88
Lloyd Avatar answered Sep 20 '22 23:09

Lloyd


Because one bit is used to store the sign (Int32 can be less than zero).

http://en.wikipedia.org/wiki/Two%27s_complement

like image 38
Jackson Pope Avatar answered Sep 18 '22 23:09

Jackson Pope