Possible Duplicate:
What is "2's Complement"?
I know int32 has a length of 32 bits (4 bytes). I assume it has 2³² values but as half of them must be under zero, I guess it has something to do with this. I would like to know why exactly int32 has max. positive number 2³¹ − 1.
Remarks. The value of this constant is 2,147,483,647; that is, hexadecimal 0x7FFFFFFF.
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.
Int32 is an immutable value type that represents signed integers with values that range from negative 2,147,483,648 (which is represented by the Int32. MinValue constant) through positive 2,147,483,647 (which is represented by the Int32. MaxValue constant. .
A 32-bit integer limit allows for 4,294,967,296 (232 2 3 2 ) pieces of data. If storing signed integers, this would range from -2,147,483,648 to 2,147,483,647.
This most significant bit is used to code the sign (1 meaning negative), so only 31 bits are available for the actual value.
Int32.MaxValue = 2^31 - 1 = 01111111111111111111111111111111
1 = 00000000000000000000000000000001
0 = 00000000000000000000000000000000
-1 = 11111111111111111111111111111111
Int32.MinValue = -2^31 = 10000000000000000000000000000000
2³² possible values
− 2³¹ values used for negative integers
− 1 value used for zero
= 2³¹ − 1 values available for positive integers
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