当前位置:网站首页>[Zhang San learns C language] - deeply understand data storage
[Zhang San learns C language] - deeply understand data storage
2022-07-02 06:47:00 【Xiexishan】
【 Zhang Sanxue C Language 】— Deep understanding of data storage
One , data type
Different data types represent the size of space opened up by different data in memory
eg:int In memory 4 Bytes
| whole type | Content Be careful : The contents in brackets are the number of bytes occupied by each type |
|---|---|
| data type | char(1 byte ) short(2 byte ) int(4 byte ) long(8 byte ) |
| floating-point | float (8 byte ) double(16 byte ) |
| Construction type | An array type ( The memory size is decided by yourself ) Structure struct ( Observe memory alignment ) enumeration enum( Memory elements determine ) Joint type union( The largest element ) |
| Pointer types | void Indicates the type , Usually used for the return type of a function , The parameters of the function , Pointer types |
C Language has no string type , So use arrays to store strings eg:char[10]="abcdef"
Two . The storage of integer data in memory
1. Source code , Inverse code , Complement code
The symbols in the computer have been stored in memory in binary form
Data is stored in memory in the form of complement
The first is the sign bit , The remaining bits are data bits
0 Being positive ,1 Negative
Source code : Direct binary can be translated into binary in the form of positive and negative numbers
Inverse code : The sign bits remain the same , The data position is reversed
Complement code : Inverse code +1
Positive numbers : Source code = Inverse code = Complement code
negative : Store... As a complement
eg:
Positive numbers
date:10
bin:00000000 00000000 00000000 00001010
Source code = Inverse code = Complement code =00000000 00000000 00000000 00001010
negative
date:-10
bin: 10000000 00000000 00000000 00001010
Inverse code :11111111 11111111 11111111 11110101
Complement code :11111111 11111111 11111111 11110110
2. The reason why data is stored in the form of complement in memory
a. The use of complement can unify the symbol bit and data field
b.CPU Only adders , Using complement can make addition and subtraction unified
3, data storage
Byte order :
Concept :cpu The order in which data in memory is accessed in bytes
Because there are high and low addresses in memory , There are high and low binary data
The host byte order mainly depends on cpu framework : X86- The small end ; MIPS- Big end
Byte order is mainly used in network communication , Communication between different hosts , If the byte order is different, it will cause data ambiguity
classification :int=0x11223344
Big end storage : The low address stores the high address Storage in memory 11 22 33 44
Small end storage : The low address stores the low address Storage in memory 44 33 22 11
notes : The size end is a high-frequency examination site in interviews and examinations , To learn more, click the link below to learn .
3、 ... and . The storage of floating-point data in memory
1,IEEE754 The standard document stipulates , The representation of any floating-point number in memory is divided into three parts
| Symbol | Memory occupied by each bit of single precision floating-point numbers | Memory occupied by each bit of double precision floating-point numbers |
|---|---|---|
| s— Sign bit | 1 A bit | 1 A bit |
| E— Exponential position | 8 A bit | 11 A bit |
| M— mantissa | 23 A bit | 52 A bit |
Floating point numbers are expressed in exponential form in the computer , Decompose into : Numeral character , mantissa , Exponential sign , Index Four parts .
The number symbol accounts for 1 Bit binary , The positive and negative of a number .0 Express positive ,1 Negative
Exponential operators account for 1 Bit binary , The positive and negative of the index .
The mantissa represents the significant number of floating-point numbers ,0.xxxxxxx, But don't save the beginning 0 Sum point .
The effective number of the index .
How many places does the index occupy , How many bits does the mantissa occupy , It's up to the computer system to decide .

Two special cases :
E For all 0: At this time, the real index value is 1-127=-126,M Represent true value , Usually used to indicate positive and negative 0
E For all 1: At this time, the real index value is 255-127=128,M For all 0 Hour means positive and negative infinity
2. Value range
| type | Number of bits | Significant figures | Range of values |
|---|---|---|---|
| float | 32 | 6-7 | -3.410(-38)~3.410(38) |
| double | 64 | 15-16 | -1.710(-308)~1.710(308) |
| long double | 128 | 18-19 | -1.210(-4932)~1.210(4932) |
If storage is more important than accuracy , Consider using float type . contrary , If accuracy is the most important condition , Then use double type .
Floating point variables can be promoted to larger Radix types ( from float Type to double type ). When you perform arithmetic on floating-point variables , Usually there will be an improvement . This arithmetic is always performed with the same precision as the variable with the highest precision .
float f_short;
double f_long;
long double f_longer;
gf_short = f_short * f_long
In the previous example , Variable f_short Promote to type double And with f_long Multiply ; then , Result rounded to type float, Then give to f_short.
3. Application example analysis
stay C and C++ in , The following assignment statement :
float a=0.1;
Compiler error :warning C4305: ‘initializing’ : truncation from 'const double ’ to 'float ’
reason : stay C/C++ in , To the right of the equal sign 0.1, Think it's a float, But the compiler thinks it's a double( Because decimals default to double), So I have to report this warning, It's usually changed to 0.1f It's all right. .
Welcome to exchange , If it works , Remember to comment + Collection + Pay attention to ! meow ~~
Today's rubbish : I didn't understand until I grew up , Nothing is difficult in the world , I'm just afraid that those who have a mind .
边栏推荐
- The intern left a big hole when he ran away and made two online problems, which made me miserable
- Win10: add or delete boot items, and add user-defined boot files to boot items
- pytest(2) mark功能
- FE - 微信小程序 - 蓝牙 BLE 开发调研与使用
- Android - Kotlin 下使用 Room 遇到 There are multiple good constructors and Room will ... 问题
- Function execution space specifier in CUDA
- Kali latest update Guide
- Latex在VSCODE中编译中文,使用中文路径问题解决
- (the 100th blog) written at the end of the second year of doctor's degree -20200818
- Sentinel Alibaba open source traffic protection component
猜你喜欢

由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决

Huawei mindspire open source internship machine test questions

20201002 VS 2019 QT5.14 开发的程序打包

table 组件指定列合并行方法

Redis - hot key issues

Fe - wechat applet - Bluetooth ble development research and use

flex九宫格布局

Shardingsphere JDBC

ctf三计

Pytest (1) case collection rules
随机推荐
ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
Alibaba cloud MFA binding Chrome browser
selenium备忘录:selenium\webdriver\remote\remote_connection.py:374: ResourceWarning: unclosed<xxxx>解决办法
Kali latest update Guide
部署api_automation_test过程中遇到的问题
[daily question 1] write a function to judge whether a string is the string after the rotation of another string.
QQ email cannot receive the email sent by Jenkins using email extension after construction (timestamp or auth...)
【文献阅读与想法笔记13】 Unprocessing Images for Learned Raw Denoising
Detailed definition of tensorrt data format
20201025 Visual Studio2019 QT5.14 信号和槽功能的使用
Fe - weex uses a simple encapsulated data loading plug-in as the global loading method
Automation - when Jenkins pipline executes the nodejs command, it prompts node: command not found
sprintf_s的使用方法
Self study table Au
Atcoder beginer contest 253 F - operations on a matrix / / tree array
uniapp引入本地字体
After reading useful blogs
20201002 VS 2019 QT5.14 开发的程序打包
eslint配置代码自动格式化
Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决