The reason why the absolute value of the maximum value of int is 1 worse than the minimum value

The decimal representation is −2147483648, converted to binary: 10000000000000000000000000000000

first place 1

It is both a sign bit and a value bit: −231=2,147,483,648

Because the sign bit is also counted as a value bit at the same time, the minimum value that can be taken is -2^31

The decimal representation is 2147483647

, converted to binary: 011111111111111111111111111111

2147483647=230+229+228+...+23+22+21+20

Because even if the sign bit is 0, the value bit is also 0, so the maximum value that can be obtained is (2^31) -1

[Note: The absolute value of the minimum value (negative number) in INT_32 is 1 greater than the absolute value of the maximum value (positive number) .

 

The range of float and double is determined by the number of digits in the exponent. References:

https://www.cnblogs.com/c-primer/p/5992696.html

Guess you like

Origin blog.csdn.net/qq_15559109/article/details/114931533