当前位置:网站首页>[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 !
边栏推荐
- Comprehensive experiment Li
- Huawei machine test questions column subscription Guide
- 2022 examination summary of quality controller civil engineering direction post skills (quality controller) and reexamination examination of quality controller civil engineering direction post skills
- XX攻击——反射型 XSS 攻击劫持用户浏览器
- 栈实现计算器
- [detailed explanation of Huawei machine test] judgment string subsequence [2022 Q1 Q2 | 200 points]
- 机动目标跟踪——当前统计模型(CS模型)扩展卡尔曼滤波/无迹卡尔曼滤波 matlab实现
- Count number of rows per group and add result to original data frame
- empirical study and case study
- Maneuvering target tracking -- current statistical model (CS model) extended Kalman filter / unscented Kalman filter matlab implementation
猜你喜欢
shardingSphere
Airsim radar camera fusion to generate color point cloud
使用beef劫持用户浏览器
01 numpy introduction
手工挖XSS漏洞
Utiliser Beef pour détourner le navigateur utilisateur
网关gateway-88
《MATLAB 神经网络43个案例分析》:第30章 基于随机森林思想的组合分类器设计——乳腺癌诊断
[detailed explanation of Huawei machine test] judgment string subsequence [2022 Q1 Q2 | 200 points]
[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order
随机推荐
Suivi des cibles de manoeuvre - - mise en oeuvre du modèle statistique actuel (modèle CS) filtre Kalman étendu / filtre Kalman sans trace par MATLAB
Five combination boxing, solving six difficult problems on campus and escorting the construction of educational informatization
程序员养生宝典
Analysis of slice capacity expansion mechanism
[Yu Yue education] Shandong Vocational College talking about railway reference materials
【入门】取近似值
Leetcode t29: divide two numbers
Aardio - Method of self constructed geticonhandle
OJ输入输出练习
【入门】提取不重复的整数
Codeworks round 803 (Div. 2) VP supplement
軟鍵盤高度報錯
Leetcode t31: prochain arrangement
【力扣10天SQL入门】Day10 控制流
golang中的正则表达式使用注意事项与技巧
2022 Chinese cook (technician) simulation test and Chinese cook (technician) practice test video
【入门】截取字符串
事务方法调用@Transactional
[getting started] input n integers and output the smallest K of them
MATLAB小技巧(16)矩阵特征向量特征值求解一致性验证--层次分析