Home Common Problem range of int type integers

range of int type integers

Jun 20, 2019 am 11:38 AM

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;
}
Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)