当前位置:网站首页>Storage of data
Storage of data
2022-07-02 05:16:00 【Smart Knight】
Catalog
2. Basic classification of data types
Two 、 The storage of integers in memory
1. Original code 、 Inverse code 、 Complement code
2. Large and small end storage
3、 ... and 、 Floating point storage in memory
3. Fetch of floating point data
One 、 data type
1. Basic built-in type
char | Character | 1byte | %c |
short | Short | 2bytes | %d |
int | plastic | 4bytes | %d |
long | Long integer | >=4bytes | %ld |
long long | Longer plastic surgery | 8bytes | %lld |
float | Single precision floating point | 4bytes | %f |
double | Double precision floating point | 8bytes | %lf |
The meaning of type :
(1) Use this type to exploit the size of memory space
(2) How to look at the perspective of memory space
2. Basic classification of data types
Type collection name | data type |
Plastic surgery Family | char unsigned char signed char |
short unsigned short signed short | |
int unsigned int signed int | |
long unsigned long signed long | |
Floating point family | float |
double | |
Construction type | An array type |
Joint type union | |
Type of structure struct | |
Enumeration type enum | |
Pointer types | int *pi; |
char *pc; | |
float* pf; | |
void* pv; | |
Empty type | void |
Two 、 The storage of integers in memory
1. Original code 、 Inverse code 、 Complement code
There are three kinds of integers in the computer 2 Decimal representation , The original code 、 Inverse and complement .
The three representations have two parts: sign bit and numeric bit , The first binary bit on the left is the sign bit , use 0 Indicates that the number is positive , use 1 Indicates that the number is negative .
The original of nonnegative integers 、 back 、 The complement is the same , The original of a negative integer 、 back 、 The complement follows the following rules .
(1) Original code : The original code can be obtained by directly translating the numerical value into binary in the form of positive and negative numbers .
(2) Inverse code : All original codes except sign bits are reversed by bits .
(3) Complement code : Add one to the inverse code to get the complement .
For plastic surgery : Data stored in memory is actually stored in the complement , And what is processed in processor operation is also complement .
also , The magic is , If you deal with the complement of negative numbers in the same way , It will change back to the original code .
Sure enough , Or my IQ is not enough .
2. Large and small end storage
(1) Definition of large and small end storage
Big end ( Storage ) Pattern : It means that 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 : It means that the low order of data is saved in the low address of memory , And the high end of the data ,, Stored in a high address in memory .
Data low and high :1000000000000
(2) Storage mode of the large and small end
We are C Define a... In the code int Variable of type a, And observe the data storage in the memory .

This is the size side storage method of shaping data , Although the storage methods are different, the compiler will restore the data in order when using variables , But modifying variables through pointers does not reorganize data in order .
The storage mode of data is only related to computer hardware , For computers we usually come into contact with , Most of them follow the small end storage method .
3. Pen test
Determine the size of the current machine
#include<stdio.h>
int main()
{
printf(" The small end \n");
return 0;
}
// be without
//▄︻┻┳═ One …… *(>○<)
// Help , I'm out of skin !!!!!!
// True code :╰(*°▽°*)╯
#include<stdio.h>
int check_sys()
{
int i = 1;
//0000 0000 0000 0000 0000 0000 0000 0001
// Big end storage :0x 00 00 00 01 Quoting ->0
// Small end storage :0x 01 00 00 00 Quoting ->1
return (*(char*)&i);
//&i Take out i The address of , And put this int* The address of type is converted to char*, Final dereference
// For big end storage , return 0; Small end storage , return 1
}
int main()
{
int ret = check_sys();
if (ret == 1)
{
printf(" The small end \n");
}
else
{
printf(" Big end \n");
}
return 0;
}3、 ... and 、 Floating point storage in memory
1. Storage rules
According to international standards IEEE( Institute of electrical and Electronic Engineering ) 754, Any binary floating point number V It can be expressed by the following formula :

- The formula :(-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 .
- stay float Type in the , The first bit is the sign bit , Back 8 Bits are stored E, final 23 Bits are stored M
- stay double Type in the , The first bit is the sign bit , Back 11 Bits are stored E, final 52 Bits are stored M

2. Detailed storage examples
for instance , We Define a float Variable , Its value is 5.5
(1) Confirm that the sign bit is 0 still 1
5.5 It's a positive number , therefore Symbol bit 0, It also corresponds to -1 Of 0 The second party is 1
(2) Convert the number from decimal to binary
Among them, the digits from the decimal point to the left represent 2 Of 0 Power ,2 Of 1 Power ,2 Of 2 Power, etc ; The digits from the decimal point to the right represent 2 Of -1 Power ,2 Of -2 Power ,2 Of -3 Power, etc . in other words ,5.5 It can be expressed as 2 Square plus 2 Of 0 Power plus 2 Of -1 Power :5.5 -> 101.1
(3) determine M And E Value
because M Is a greater than 1 Less than 2 The number of , So for 101.1 Can be seen as 1.011 multiply 2 The square of , At this point, we have determined M=1.011,E=2, however because M Greater than 1 Less than 2 Characteristics of ,M The one before the decimal point will not be stored in memory , In this way, we can make the best use of space to ensure accuracy .
(4)E The storage
Because floating point data is stored E Can only be stored as an unsigned integer , So stored in floating-point type E Is its calculated value , The calculated value is equal to the real value plus the intermediate value , stay float The intermediate value in the type is 127,double The intermediate value in the type is 1023
E The real value of is 2, Variable is float type , The value stored in memory is 129:10000001
This is it. float Type of 5.5 Storage of :
Sign bit (S) | Exponential position (E) | Significant figures (M) |
0 | 10000001 | 01100000000000000000000 |
(5) We often talk about precision when using floating-point data , It proves that some floating-point data cannot be accurately stored in memory .
for instance , Let's define a float Variables of type are merged into binary numbers :3.6 ->11.100110011001100110011001100110011001100110011001101
This number of M It has long exceeded the number of bits that can be stored , This number cannot be stored accurately , This is why we emphasize precision when describing floating-point numbers .
3. Fetch of floating point data
However , Index E Fetching from memory can be further divided into three cases :
(1)E Not all for 0 Or not all of them 1
At this time , Floating point numbers are represented by the above rules , That is, find the sign bit first , Then index E The calculated value of minus 127( or 1023), Get the real value , then
Significant figures M Add the first 1.
(2)E All for 0
At this time , The exponent of a floating point number E be equal to 1-127( perhaps 1-1023) That's the true value ,
Significant figures M No more first 1, It's reduced to 0.xxxxxx Decimals of . This is to show that ±0, And close to
0 A very small number of .
(3)E All for 1
At this time , If the significant number M All for 0, Express ± infinity ( It depends on the sign bit s)
边栏推荐
- Here comes the chicken soup! Keep this quick guide for data analysts
- ansible安装与使用
- js中的Map(含leetcode例题)
- Global and Chinese market of hydrocyclone desander 2022-2028: Research Report on technology, participants, trends, market size and share
- el form 表单validate成功后没有执行逻辑
- Essence and physical meaning of convolution (deep and brief understanding)
- LS1046nfs挂载文件系统
- Fabric.js 基础笔刷
- Dark horse notes -- map set system
- [high speed bus] Introduction to jesd204b
猜你喜欢

Fabric.js IText设置指定文字的颜色和背景色

Lay the foundation for children's programming to become a basic discipline

数据库问题汇总

数据的储存

数学知识(欧拉函数)

Pycharm breakpoint management: temporarily cancel some breakpoints + run directly to a line

Collectors.groupingBy 排序

Go Chan's underlying principles

Differential identities (help find mean, variance, and other moments)

指针使用详解
随机推荐
LeetCode 241. 为运算表达式设计优先级(分治/记忆化递归/动态规划)
数据库批量插入数据
List of common bugs in software testing
National all Chinese Automatic Test Software apifox
Pyflink writes MySQL examples with JDBC
7.1模擬賽總結
[bus interface] Axi interface
Collectors. Groupingby sort
國產全中文-自動化測試軟件Apifox
LeetCode 1175. Prime number arrangement (prime number judgment + Combinatorial Mathematics)
Global and Chinese market of commercial fish tanks 2022-2028: Research Report on technology, participants, trends, market size and share
Leetcode basic programming: array
A new attribute value must be added to the entity entity class in the code, but there is no corresponding column in the database table
线程池批量处理数据
Here comes the chicken soup! Keep this quick guide for data analysts
Simple and practical accounting software, so that accounts can be checked
LeetCode 1175. 质数排列(质数判断+组合数学)
Super detailed pycharm tutorial
農業生態領域智能機器人的應用
Gee: find the spatial distribution and corresponding time of the "greenest" in the Yellow River Basin in 2020 [pixel by pixel analysis]