当前位置:网站首页>C Advanced - data storage (Part 1)
C Advanced - data storage (Part 1)
2022-07-06 05:18:00 【Stardust will not fall】
Data storage
1 Data type introduction
Basic built-in type :
char // Character data type
short // Short
int // plastic
long // Long integer
long long // Longer plastic surgery
float // Single-precision floating-point
double // Double precision floating point
The meaning of type :
- Use this type to exploit the size of memory space ( Size determines the range of use ).
- How to look at the perspective of memory space .
1.1 Basic classification of types :
Plastic surgery Family :
char
unsigned char
signed char
short
unsigned short [int]
signed short [int]
int
unsigned int
signed int
long
unsigned long [int]
signed long [int]
Floating point family :
float
double
Construction type :
An array type
Type of structure struct
Enumeration type enum
Joint type union
Pointer types :
int pi;
char pc;
float pf;
void pv;
Empty type :
void Indicates empty type ( No type )
Usually applied to the return type of a function 、 The parameters of the function 、 Pointer types .
2. Shaping storage in memory
The creation of a variable is to open up space in memory . The size of space is determined according to different types .
Next, let's talk about how data is stored in the opened memory .
such as :int a = 20; int b = -10;
2.1 Original code 、 Inverse code 、 Complement code
There are three ways to represent integers in a computer , The original code 、 Inverse and complement .
The three representations have two parts: sign bit and numeric bit , The sign bits are all used 0 Express “ just ”, use 1 Express “ negative ”, The three representations of numeric bit negative integers are different .
Original code :
Directly translate binary into binary in the form of positive and negative numbers .
Inverse code :
Change the sign bit of the original code , The other bits can be inverted in turn .
Complement code :
Inverse code +1 You get the complement .
A positive number 、 back 、 The complement is the same .
For plastic surgery : Data stored in memory is actually stored in the complement .
In computer system , All values are represented and stored by complements . The reason lies in , Use complement , Symbol bits and value fields can be treated in a unified way ;
meanwhile , Addition and subtraction can also be handled in a unified way (CPU Only adders ) Besides , Complement code and original code are converted to each other , Its operation process is the same , No need for additional hardware circuits .
Let's look at the storage in memory :

2.2 Introduction to big and small end
What big end, small end :
Big end ( Storage ) Pattern , The low bit of data is stored in the high address of memory , And the high end of the data , Stored in a low address in memory ;
The small end ( Storage ) Pattern , The low bit of data is stored in the low address of memory , And the high end of the data ,, Stored in memory
Address .
Why there are big end and small end :
Why are there big and small end patterns ? This is because in a computer system , We are in bytes , Each address corresponds to a byte , A byte is 8bit. But in C In language, except 8 bit Of char outside , also 16 bit Of short type ,32 bit Of long type ( It depends on the specific compilation
Translator ), in addition , For digits greater than 8 Bit processor , for example 16 Bits or 32 Bit processor , Because the register width is larger than one byte , So there must be a problem of how to arrange multiple bytes . So it leads to big end storage mode and small end storage mode .
for example : One 16bit Of short type x , The address in memory is 0x0010 , x The value of is 0x1122 , that 0x11 For high byte , 0x22 Is low byte . For big end mode , will 0x11 Put it in the low address , namely 0x0010 in , 0x22 Put it in a high address , namely 0x0011 in . The small end model ,
Just the opposite . That we use a lot X86 The structure is small end mode , and KEIL C51 It's the big end mode . A great deal of ARM,DSP It's all small end mode . There are some ARM The processor can also choose the big end mode or the small end mode by the hardware .

边栏推荐
- Postman Association
- 图论的扩展
- Drive development - the first helloddk
- [lgr-109] Luogu may race II & windy round 6
- Rce code and Command Execution Vulnerability
- Unity gets the width and height of Sprite
- Summary of three log knowledge points of MySQL
- Biscuits (examination version)
- MySQL if and ifnull use
- 2022 half year summary
猜你喜欢

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Postman assertion

Safe mode on Windows

CUDA11.1在线安装

剑指 Offer II 039. 直方图最大矩形面积

Principle and performance analysis of lepton lossless compression

Cuda11.1 online installation

Using stopwatch to count code time

Cve-2019-11043 (PHP Remote Code Execution Vulnerability)

Crazy God said redis notes
随机推荐
Golang -- TCP implements concurrency (server and client)
Imperial cms7.5 imitation "D9 download station" software application download website source code
[classic example] binary tree recursive structure classic topic collection @ binary tree
Oracle deletes duplicate data, leaving only one
[leetcode] 18. Sum of four numbers
【torch】|torch.nn.utils.clip_grad_norm_
Using stopwatch to count code time
[buuctf.reverse] 159_ [watevrCTF 2019]Watshell
Postman manage test cases
驱动开发——第一个HelloDDK
UCF (2022 summer team competition I)
Summary of redis basic knowledge points
Talking about the type and function of lens filter
2021RoboCom机器人开发者大赛(初赛)
Three.js学习-光照和阴影(了解向)
February 12 relativelayout
Nestjs配置文件上传, 配置中间件以及管道的使用
Compilation and connection of shader in games202 webgl (learn from)
Nacos - TC Construction of High available seata (02)
Lepton 无损压缩原理及性能分析