<> Talking about C Data storage in language

The storage of a variable needs to open up new space in memory , Let's have a deep understanding today C Data storage in language .
C Data storage in language , It can be divided into four aspects :
1. Data type introduction
2. Shaping storage in memory : Original code , Inverse code , Complement
3. Introduction and judgment of byte order of big and small end
4. Analysis of floating point storage in memory

<> Data type introduction

The meaning of type : The size of memory space opened up with this type ( Size determines range )
Basic classification of types :
Plastic surgery Family , Floating point family , Tectonic type , Pointer type , Null type (void)

<> Shaping storage in memory

Next, we talk about how to store data in the memory
example :
int a=10;
int Is an integer variable , open up 4 A space of two bytes a.
When we want to explore how to store , Let's look at the original code first , Inverse and complement .
Original code , Inverse and complement
There are three expressions of signed number in computer , Original code , Inverse and complement .
There are sign bits and numeric bits in the three representations , Symbol bit “0” Show positive ,“1” It means negative .
Original code
Translate numbers directly into binary
Inverse code
Keep the sign bit of the original code unchanged , The other bits can be reversed in turn
Complement
Inverse code +1 Get the complement
The primitive of positive numbers , back , All complements are the same
In computer system , All numerical values are expressed and stored by complements . The reason is that , Use complement , The symbol bit and the numeric field can be unified ; with
Time , Addition and subtraction can also be dealt with in a unified way (CPU Only adders ) in addition , Mutual conversion between complement code and original code , The operation process is the same , No need Additional hardware circuits are required .

The number in memory is hexadecimal , So why isn't it shown 00 00 00 01 What about it ?
Here is another point of knowledge —— Big end / Small end storage
Introduction and judgment of byte order of big and small end
What is big / Small end storage ?
Big end storage : Save the low bit of data to the high address of memory , The high bit is stored in the low address
Small end storage : Store the high bit in the data to the high address in the memory , The low bit is stored in the low address
Notation : The big end is opposite , A short photo
How to judge the current machine size / Small end storage ?
int main() { int a=1; char* p=(char*)&a;//a Cast bit char*, Take one character if(*p==1) { printf(
" Small end \n"); } else { printf(" Big end "); } return 0; }
<> Analysis of floating point storage in memory

According to international standards , Any binary floating point number can be expressed in the following form :
(-1)^S * M * 2^E
(-1)^S Symbol bit ,s = 0 Be positive s = 1 It's negative
M Represents a significant number , greater than 1 less than 2
2^E Indicates the exponent
example : decimal system 5.0, Write in binary 101.0, amount to 1.01x2^2. Can exit S = 0, M = 1.01,E=2
IEEE 754 regulations : about 32 Bit floating point number , highest 1 Bit is sign bit S, Come down 8 Digit index E, The rest is 23 Significant number M.

Single precision floating point
IEEE745 Where is the significant number M And index E, There are some special requirements
Significant number M:1<=M<2
IEEE
754 regulations , Save it inside the computer M Time , By default, the first digit of this number is always 1, So it can be discarded , Save only the following xxxxxx part . For example, preservation 1.01 When I was young , Save only 01, Wait until it's read , And the first one 1 Add it up . The purpose of doing so , It's saving 1 Three significant digits . with 32 Take the floating point number as an example , For M only 23 position , Will be the first 1 After giving up , It means it can be saved 24 Three significant digits
index E: The situation is quite special
first E Is an unsigned integer , If E yes 8 position Its value range 0 - 255; If E yes 11 position Its value range 0 -
2047. But we know that in scientific counting E Negative numbers are possible , therefore **IEEE754 regulations
: When stored in memory E The true value of must be added with an intermediate number , about 8 Positional E, The middle number is 127; about 11 Positional E, Intermediate number 1023.** for example :2^10 Of E yes 10, So save it as 32 Bit floating point number , Must be saved as 10+127=137, Namely 10001001
index E There are three situations when fetching from memory :
1,E Not all 0 Or not all 1

At this time , Floating point numbers are represented by the following rules , The index E Subtract the calculated value of 127( or 1023), Get the real value , Then add the significant number M First and foremost 1. such as :
0.5(1/2) The binary form of is 0.1, Because the positive part must be 1, That is to move the decimal point to the right 1 position , Then 1.0*2^(-1), Its order code is -1+127=126, Expressed as 01111110, And the mantissa 1.0 Remove the integer part to 0, Make up 0 reach 23 position 00000000000000000000000, The binary representation is 0
01111110 00000000000000000000000

2,E All for 0

At this time , Index of floating point numbers E be equal to 1-127( perhaps 1-1023) This is the true value ,
Significant number M No more first 1, Instead, it's reduced to 0.xxxxxx Decimals of . This is to show that ±0, And close to 0 It's a very small number

3,E All for 1

At this time , If significant number M All for 0, express ± Infinity ( The positive and negative depend on the sign bit s)

Technology
©2019-2020 Toolsou All rights reserved,
Hikvision - Embedded software written test questions C Language application 0 The length of array in memory and structure is 0 In depth analysis data structure --- The preorder of binary tree , Middle order , Subsequent traversal How to do it ipad Transfer of medium and super large files to computer elementui Shuttle box el-transfer Display list content text too long 2019 The 10th Blue Bridge Cup C/C++ A Summary after the National Games ( Beijing Tourism summary )unity Shooting games , Implementation of first person camera python of numpy Module detailed explanation and application case Study notes 【STM32】 Digital steering gear Horizontal and vertical linkage pan tilt Vue Used in Element Open for the first time el-dialog Solution for not getting element