当前位置:网站首页>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)
边栏推荐
- Pyechats 1.19 generate a web version of Baidu map
- Gee data set: export the distribution and installed capacity of hydropower stations in the country to CSV table
- Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
- LS1046nfs挂载文件系统
- Implementation of go language for deleting duplicate items in sorting array
- Fabric.js 右键菜单
- Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]
- Leetcode basic programming: array
- Gee: find the spatial distribution and corresponding time of the "greenest" in the Yellow River Basin in 2020 [pixel by pixel analysis]
- Fasttext text text classification
猜你喜欢
Gee data set: export the distribution and installed capacity of hydropower stations in the country to CSV table
How to configure PostgreSQL 12.9 to allow remote connections
LeetCode 241. Design priorities for operational expressions (divide and conquer / mnemonic recursion / dynamic programming)
ansible安装与使用
Gee: use of common mask functions in remote sensing image processing [updatemask]
Nodejs (03) -- custom module
Knowledge arrangement about steam Education
Disable access to external entities in XML parsing
关于Steam 教育的知识整理
農業生態領域智能機器人的應用
随机推荐
Fabric.js 更换图片的3种方法(包括更换分组内的图片,以及存在缓存的情况)
Global and Chinese market of commercial fish tanks 2022-2028: Research Report on technology, participants, trends, market size and share
Preparation for writing SAP ui5 applications using typescript
7.1 simulation summary
Global and Chinese market of impact roll 2022-2028: Research Report on technology, participants, trends, market size and share
Find the subscript with and as the target from the array
2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas
Global and Chinese market of pressure gauges 2022-2028: Research Report on technology, participants, trends, market size and share
Lay the foundation for children's programming to become a basic discipline
06 decorator mode
Simple and practical accounting software, so that accounts can be checked
Fabric.js IText设置指定文字的颜色和背景色
How to make an RPM file
指针使用详解
数学知识(欧拉函数)
LeetCode 1175. 质数排列(质数判断+组合数学)
延时队列两种实现方式
LeetCode 241. Design priorities for operational expressions (divide and conquer / mnemonic recursion / dynamic programming)
2022阿里巴巴全球数学竞赛 第4题 虎虎生威(盲盒问题、集卡问题)解决思路
[quick view opencv] familiar with CV matrix operation with image splicing examples (3)