当前位置:网站首页>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)
边栏推荐
- Mathematical knowledge (Euler function)
- LeetCode 241. Design priorities for operational expressions (divide and conquer / mnemonic recursion / dynamic programming)
- [common error] the DDR type of FPGA device is selected incorrectly
- 画波形图_数字IC
- Pycharm breakpoint management: temporarily cancel some breakpoints + run directly to a line
- Dark horse notes -- Set Series Collection
- 数据的储存
- Leetcode basic programming: array
- 黑马笔记---Set系列集合
- Essence and physical meaning of convolution (deep and brief understanding)
猜你喜欢

Fabric.js IText 手动设置斜体

数学问题(数论)试除法做质数的判断、分解质因数,筛质数

CubeMx DMA笔记

Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
![[opencv] image binarization](/img/7e/b56a59ffae3bf6cac9c0bb7e090b85.jpg)
[opencv] image binarization

Nodejs (03) -- custom module

2022阿里巴巴全球数学竞赛 第4题 虎虎生威(盲盒问题、集卡问题)解决思路

Mathematical knowledge -- understanding and examples of fast power

黑马笔记---Map集合体系

Gee: create a new feature and set corresponding attributes
随机推荐
Global and Chinese market of pressure gauges 2022-2028: Research Report on technology, participants, trends, market size and share
Gee: explore the characteristics of precipitation change in the Yellow River Basin in the past 10 years [pixel by pixel analysis]
paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
Oracle和MySQL的基本区别(入门级)
Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
Go GC garbage collection notes (three color mark)
7.1 Résumé du concours de simulation
The underlying principle of go map (storage and capacity expansion)
Gee: create a new feature and set corresponding attributes
Video multiple effects production, fade in effect and border background are added at the same time
Essence and physical meaning of convolution (deep and brief understanding)
ansible安装与使用
How to configure PostgreSQL 12.9 to allow remote connections
案例分享|智慧化的西部机场
Go implements leetcode rotation array
Mathematical knowledge (Euler function)
C# 基于MQTTNet的服务端与客户端通信案例
Fabric.js 居中元素
Here comes the chicken soup! Keep this quick guide for data analysts
Latest: the list of universities and disciplines for the second round of "double first-class" construction was announced