当前位置:网站首页>[deep analysis of C language] - data storage in memory
[deep analysis of C language] - data storage in memory
2022-07-01 08:29:00 【Shark-s】
List of articles
Preface
In the previous blog , We've covered the basic built-in types , As follows
char // Character data type
short // Short
int // integer
long // Long integer
long long // Longer integers
float // Single-precision floating-point
double // Double precision floating point
Today we will analyze these built-in types on this basis , Let us have a deeper understanding of it
1️⃣ Data type introduction
1. The integer 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]
among char It's also part of the integer family , because char In memory, I use ASCII Worth storing in form , It can be regarded as a special integer .
2. Floating point family 🧡
float
double
3. Construction type
An array type
Type of structure struct
Enumeration type enum
Joint type union
4. Pointer types
int pi;
char pc;
float pf;
void pv;
2️⃣ The storage of data in memory
1. The storage of integers in memory 🤎
Before you know how to store shaping , Let's introduce : Original code 、 Inverse code 、 Complement code .
There are three ways to express the number of symbols in a computer , The original code 、 Inverse and complement . The three methods have two parts: sign bit and value bit .
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 .
The original code of a positive number 、 Inverse code 、 The complement is the same .
For plastic surgery : Data stored in memory is actually stored in the complement .
There is also a reason :
Use complement , Symbol bits and value fields can be treated in a unified way ;
Addition and subtraction can also be handled in a unified way (CPU Only adders );
Complement code and original code are converted to each other , Its operation process is the same , No need for additional hardware circuits .
2. Floating point storage in memory
According to international standards IEEE 754, Any binary floating point number V It can be expressed in the following form :
· (-1)^S * M * 2^E.· (-1)^S The sign bit , When S == 0, V Is a positive number ; When S == 1, V It's a negative number .
· M Represents a significant number , Greater than or equal to 1, Less than 2、
· 2^E Indicates the index bit .
IEEE 754 Regulations : about 32 Bit floating point , The highest 1 Bits are sign bits S, And then 8 Bits are exponents E, The rest 23 Bits are significant numbers M.
E Two special values of :
E All for 0:
When E All for 0 When , namely 2 To the power of 0 - 127 by 2^-127 Power , therefore , When s = 0 when , A positive number 2^-127 Power , It is a wireless approach from the right of the number axis to 0 The number of ; And when s = 1 when , A negative number 2^-127 The power is from the left of the number axis to 0 The number of .
So when E All for 0 When , Actually, it means ±0, So floating point numbers cannot appear in programs And 0 To compare ( Floating point numbers == 0), But to compare with a range .
E All for 1:
When E All for 1 When ( If M All for 0), namely 2 To the power of 255 - 127 = 128, So when S = 0 when , Express 1 * 2^128 Power , When s = 1 It means -1*2^128 Power .
So when E All for 1 when , In fact, it represents the value range of this floating-point number .
3️⃣ summary
The above is a description of how data is stored in memory
If there is anything improper , Hope to point out !
边栏推荐
- 数字转excel的字符串坐标
- empirical study and case study
- 手工挖XSS漏洞
- 使用beef劫持用戶瀏覽器
- Yolov5 advanced 7 target tracking latest environment setup
- When using charts to display data, the time field in the database is repeated. How to display the value at this time?
- Leetcode t31: next spread
- OJ input and output exercise
- 【Redis】一气呵成,带你了解Redis安装与连接
- Chinese font Gan: zi2zi
猜你喜欢

Airsim radar camera fusion to generate color point cloud

MATLAB小技巧(23)矩阵分析--模拟退火
![[untitled]](/img/be/3523d0c14d555b293673af2b6fbcff.jpg)
[untitled]

Maneuvering target tracking -- current statistical model (CS model) extended Kalman filter / unscented Kalman filter matlab implementation

【入门】输入整型数组和排序标识,对其元素按照升序或降序进行排序
![[untitled]](/img/b9/6922875009c2d29224a26ed2a22b01.jpg)
[untitled]
![[question brushing] character statistics [0]](/img/cc/f5aaecd920c502180303d92447e54f.png)
[question brushing] character statistics [0]

Serial port oscilloscope software ns-scope
![[getting started] extract non repeating integers](/img/88/3e96df88e980bd98ac112b18a8678c.png)
[getting started] extract non repeating integers

CPU設計實戰-第四章實踐任務一簡單CPU參考設計調試
随机推荐
【入门】输入n个整数,输出其中最小的k个
機動目標跟踪——當前統計模型(CS模型)擴展卡爾曼濾波/無迹卡爾曼濾波 matlab實現
Gateway-88
軟鍵盤高度報錯
Leetcode t31: next spread
01 NumPy介绍
Provincial election + noi Part III tree problems
Field agricultural irrigation system
使用 setoolkit 伪造站点窃取用户信息
Stack implementation calculator
Using settoolkit to forge sites to steal user information
2022 ordinary scaffolder (special type of construction work) examination question bank and the latest analysis of ordinary scaffolder (special type of construction work)
手工挖XSS漏洞
Yolov5 advanced six target tracking environment construction
Provincial election + noi part I dynamic planning DP
Intelligent water and fertilizer integrated control system
MAVROS发送自定义话题消息给PX4
EDA开源仿真工具verilator入门6:调试实例
SPL-安装与基本使用(二)
On several key issues of digital transformation