The basic data type of data-integer

In the C language, there are only four basic data types-integer, floating-point, pointer and aggregate types (such as arrays and structures, etc.). All other types are derived from some combination of these four basic types. This blog only involves integers

1. Integer family The
integer family includes characters, short integers, integers and long integers. They are divided into two versions, signed and unsigned.
It sounds like the value that the "long integer" can represent should be larger than the value that the "short integer" can represent, but this assumption is not necessarily correct. The rules governing the mutual size of integer values ​​are quite simple:
long integers should be at least as long as integers, and integers should be at least as long as short integers.
Note : The C language standard does not stipulate that the long integer must be longer than the short integer, but it is stipulated that it cannot be shorter than the short integer. In order to better illustrate the minimum allowable range of various integer values. We introduce a table here for everyone to understand

Types of Minimum range
char 0 to 127
signed char -127 to 127
unsigned char 0 to 256
short int -32767 to 32767
unsigned short int 0 to 65535
int -32767 to 32767
unsigned int 0 to 65535
long int -2417483647 to 2147483647
unsigned long int 0 to 4294967295

1.1 Integer storage
We all know that the storage of data is to open up space in the memory, but in what way is the data stored in the open space?
Take a chestnut: We all know that a is an integer, and the memory needs to allocate four bytes of space for a, but how should a be stored? Here we first understand the concepts of the following nouns: original code, one's complement, and one's complement There are three ways to represent signed numbers in computers, namely, original code, one's complement and one's complement. The three representation methods have two parts: the sign bit and the value bit. The sign bit uses 0 to indicate "positive" and 1 to indicate "negative", while the three representation methods of the value bit are different. The original code directly translates the binary into binary according to the form of positive and negative numbers, and the inverse code can be obtained. The sign bit of the original code remains unchanged, and the other bits are inverted sequentially by bit. Complement Code Add 1 to the inverse code to get the complement code. The original, inverse, and complement of a positive number are all the same. For plastic shaping: the data storage memory actually stores the complement code. After reading the way the data is stored in the memory, let's look at another question:
int a=10; int b=20;














#include<stdio.h>
int main()
{
    
    
	int a=-20;
	unsigned int b=10;
	
	printf("%d",a+b);
}

Everyone can tell the answer, but how does the process look like? Let's look at the following analysis
Insert picture description here

We add the two complements of the two numbers and then invert the bits by +1 to get the original code and then output. The
final original code is: 10000000 00000000 00000000 00001010 The
final result is 10!

Guess you like

Origin blog.csdn.net/ahuyccc/article/details/111464649