Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What is the maximum value of int type in 32-bit operating system?
What is the maximum value of int type in 32-bit operating system?

The maximum value of the int type in 32-bit operating systems is ?2147483647.

The value range of int type under 32-bit operating system is as follows:

1. Int32 //Equal to int, occupying 4 bytes (-2147483648~2147483647).

2. Int8? //Equal to byte,

3. Int16 //Equal to short, occupying 2 bytes (-32768~32767).

4. Int64 //Equal to long, occupies 8 bytes (-9223372036854775808~9223372036854775807).

Question 1: The concepts of signed int and int are different.

Int is signed int. When writing in books, [signed] int is used to indicate that signed can be omitted. The default for int is signed int, which means it is a signed integer. The highest bit is the sign bit, and the data Only 31 positions are occupied.

Unsigned int is an unsigned integer, the highest bit is also the data bit, and the data occupies 32 bits.

Each variable type has two types: unsigned and signed (float and double are always signed). Integer variables declared by default are It is a signed type (char is a bit special). If you need to declare an unsigned type, you need to add unsigned before the type.

The difference between the unsigned version and the signed version is that the unsigned type can store 2 times the positive integer data of the signed type.

Question 2: On a 32-bit platform, the maximum value that can be assigned to the int type is: 2147483647 (2^31-1), and the maximum value that can be assigned to the unsigned int type is: 4294967295 (2^32-1).

The range of data that an int can store in a 16-bit system is -32768~32767, while the range of data that unsigned can store is 0~65535. Because in computers, integers are stored in two's complement form.

Question 3: When int is assigned a value of 4294967295, syntax analysis will consider it to be an unsigned int value, so its value range is: 0~4294967295.

Int is a function that rounds a value down to the nearest integer. INT is a rounding function among common functions in databases. It is often used to determine whether a number is divisible by another number.

In computers, there are three ways to encode numbers: original code, complement code, and inverse code. The original code is actually the result of converting a decimal number directly into a binary number. For example: 18 in decimal is 10010 in binary. Then 10010 here is the original code.

You can sizeof how many bytes the int type occupies on your computer. Mine is 4 bytes, which means there are only 32 bits. If the number of converted binary digits of a decimal number is greater than 32, it will overflow, which means it cannot be stored.

There are not only positive numbers but also negative numbers in stored numbers. How to distinguish positive and negative numbers in a computer? We stipulate that the highest bit is the sign bit. A value of 0 is positive and a value of 1 is negative. Therefore, the highest bit cannot be included in the calculation.

For example, if the highest bit of the binary number 1000 is the sign bit, the decimal conversion is not 8, but -0, which is negative 0 (the binary form of positive 0 is 0000). If given a negative number in decimal form, how to calculate its complement?

1. Calculate the binary representation of the absolute value of this number.

2. Write 2^n in binary form and subtract this number to get the complement.

For example: -5,

The binary form of 1 and 5 is: 0101. The highest bit is the coincidence bit, and 0 is positive.

2., 1111-101, binary subtraction, the complement is 1010. The highest bit is the coincidence bit, and 1 is negative.

So, when int occupies 32 bits, the maximum value that can be assigned is: 2147483647. That is 0x7ffffffff. Note: The highest bit of the binary form of 7 is 0. If 2147483647+1 is added, the output is -2147483648.

This number is the largest number among negative numbers, that is, the smallest negative number that can be represented by the int type. Its hexadecimal representation is: 0x8fffffff. The highest bit of the binary form of 8 is the sign bit, which is 1, which is negative.

Extended information:

Explanation of the maximum value of int in C language:

1. 16-bit compiler explanation: int occupies 16 bits. 2 bytes of memory. Maximum value: 32767.

int a=10000000000; int b=124564837443; int c=33443;

2. 32-bit and 64-bit compilers: int occupies 32 bits. 4 bytes of memory. Maximum value: 21474836473. As the number of digits increases, the number of natural digits also doubles.

int x=sizeof(a);int y=sizeof(b);int z=sizeof(c);

The main reason for determining the maximum value of int, according to the compiler type vary with each other. Therefore, some written programs cannot successfully run on the computer. Most of them have something to do with the compiler, and may not be the cause of the program.

In general program expression, the highest bit is the sign bit, and when the number of bits is n, the maximum value is 2^(n-1), which is the n-1 power of 2.

In the compiler, you can use sizeof(int) to check the number of bytes occupied, and print the obtained value on the console through pintf.

Reference material: Baidu Encyclopedia-Byte

Reference material: Baidu Encyclopedia-INT (rounding function Int())

Reference material: Baidu Encyclopedia- unsigned int