range of int

int decimal: -2^31=-21 4748 3648 to 2^31-1=21 4748 3647. A total of 10, 2.1 billion.

In a 32-bit or 64-bit machine, an int occupies 4 bytes, or 32 bits. (one byte, 8 bits)

The largest positive integer that int can represent is:

0111 1111 1111 1111 1111 1111 1111 1111 (the highest bit represents the sign bit, the positive sign bit is 0), the corresponding decimal number is 2^31-1=2147483647, and the corresponding hexadecimal representation is: 0x7FFFFFFF.

The smallest negative integer that int can represent is:

1000 0000 0000 0000 0000 0000 0000 0000 (the highest bit represents the sign bit, and the sign bit of negative numbers is 1). Negative numbers exist in the form of complement code, so the corresponding original code (the complement code of complement) is also 1000 0000 0000 0000 0000 0000 0000 0000, the corresponding hexadecimal representation is 0x80000000, and C/C++ specifies that the value is -2^31=-2147483648.

      

So in the end, the range of the int type (integer type) is -2^31 ~ 2^31-1, that is, -2147483648~2147483647, in hexadecimal representation: 0x80000000~0x7FFFFFFF.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325648827&siteId=291194637