Home  >  Article  >  range of int type integers

range of int type integers

尚
Original
2019-06-20 11:38:3176782browse

range of int type integers

The range of int is -2147483648~2147483647.

The calculation method is as follows:

The range of 32-bit int type variables in the computer, where the int type is a signed integer.

Positive numbers are expressed as original codes in the computer, and the highest bit is the sign bit: The original code of

1 is the original code of 0000 0000 0000 0000 0000 0000 0000 0001

2147483647 The code is 0111 1111 1111 1111 1111 1111 1111 1111

So the largest positive integer is 2147483647

Negative numbers are represented as complement codes in the computer, and the highest bit is the sign bit:

-1:

The original code is 1000 0000 0000 0000 0000 0000 0000 0001, the inverse code of

is 1111 1111 1111 1111 1111 1111 1111 1110, the complement code of

is 1111 1111 1111 1111 1111 1111 1111 1111

-2147483647: The original code of

is 1111 1111 1111 1111 1111 1111 1111 1111, the reverse code of

is 1000 0000 0000 000 0 0000 0000 0000 0000 ,

The complement is 1000 0000 0000 0000 0000 0000 0000 0001

So the smallest negative number is -2147483647? Wrong, no.

In binary, there are two table methods for 0.

The original code of 0 is 0000 0000 0000 0000 0000 0000 0000 0000, the original code of

-0 is 1000 0000 0000 0000 0000 0000 0000 0000,

because 0 is only One is needed, so use -0 as the smallest number -2147483648. The complement code of

-2147483648 is expressed as 1000 0000 0000 0000 0000 0000 0000 0000. There is no original code in 32 bits.

Note that this complement is not the real complement. The real complement is 1 1000 0000 0000 0000 0000 0000 0000 0000, which is an overflow.

So the signed 32-bit int type integer is -2147483648~2147483647

Programming can directly call the function to find the range:

#include <limits.h>
#include<stdio.h>
int max = INT_MAX;//最大数
int min = INT_MIN;//最小数
int main(){
printf("max = %d\nmin = %d\n", max, min);
return 0;
}

range of int type integers

The above is the detailed content of range of int type integers. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn