当前位置:网站首页>C language - data storage
C language - data storage
2022-06-11 12:44:00 【Xiaolock830】
**
data type
**
char // Character data type
short // Short
int // plastic
long // Long integer
long long// Longer plastic surgery
float // Single-precision floating-point
double // Double precision floating point
The memory size of these data types can be found in my first blog , The preceding types all have corresponding unsigned The type and signed type , That is, signed type and unsigned type , In theory, unsigned ones can store larger numbers .
If there's no unsigned, Then the default is signed .
char
unsigned char
signed char
short
unsigned short [int]
signed short [int]
int
unsigned int
signed int
long
unsigned long [int]
signed long [int]
Empty type :
void Indicates empty type
Usually applied to the return type of a function 、 The parameters of the function 、 Pointer types .
**
Plastic storage :
**
Original code 、 Inverse code 、 Complement code :
Original code
Directly translate binary into binary in the form of positive and negative numbers
Inverse code
Change the sign bit of the original code , The other bits can be inverted in turn .
Complement code
Inverse code +1 You get the complement .
A positive number 、 back 、 The complement is the same .
For plastic surgery : Data stored in memory is actually stored in the complement .
Why is data stored as a complement :
In computer system , All values are represented and stored by complements . The reason lies in , Use complement , You can combine sign bits and numeric fields One processing ;
meanwhile , Addition and subtraction can also be handled in a unified way (CPU Only adders ) Besides , Complement code and original code are converted to each other , Its operation process It's the same , No need for additional hardware circuits .
Big end and small end :
Big end ( Storage ) Pattern , 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 , The low bit of data is stored in the low address of memory , And the high end of the data , Stored in a high address in memory .
Judge the size of the machine :
#include <stdio.h>
int check_sys()
{
int i = 1;
return (*(char *)&i);
}
int main()
{
int ret = check_sys();
if(ret == 1)
{
printf(" The small end \n"); }
else
{
printf(" Big end \n");
}
return 0;
}
Floating point storage :
According to international standards IEEE( Institute of electrical and Electronic Engineering ) 754, Any binary floating point number V It can be expressed in the following form :
(-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 .
For example, decimal 5.0, Written as binary is 101.0 , amount to 1.01×2^2 .
that , According to the above V The format of , We can draw s=0,M=1.01,E=2.
Decimal -5.0, Written as binary is -101.0 , amount to -1.01×2^2 . that ,s=1,M=1.01,E=2.
In memory , This is how we allocate floating point numbers :
about 32 Floating point number of bits , The highest 1 Bits are sign bits s, And then 8 Bits are exponents E, The rest 23 Bits are significant numbers M.
We can find out , Write the above form for any number ,M First of all 1, So ignore this when saving to memory 1.
And for less than 1 Number of numbers ,E The storage of may be negative , The storage range will be reduced by half due to the storage of negative numbers , So we E Change to an unsigned positive number , When storing , If it is 8 Bit E You need to add 127,11 Bit plus 1023
边栏推荐
- Audio adaptation of openharmony Standard System Porting
- Redis data type daily use scenarios
- Where is it safer to open an account for soda ash futures? How much is the margin for soda ash futures?
- What are the profit sources of mother and baby stores?
- 室内场馆现代化的三大要点
- 罗景:连接效率优化实践
- PADS使用之繪制原理圖
- 秒杀整体的技术难点
- 9. Talk about ThreadLocal
- Redis数据类型日常使用场景
猜你喜欢

Evolution of e-commerce development

Ways to double the summer performance of natatoriums

Adobe Premiere foundation - batch material import sequence - variable speed and rewind (recall) - continuous action shot switching - subtitle requirements (13)

How does Wireshark modify the display format of packet capturing time and date?

How Oracle exports data to CSV (Excel) files

2022年618投影仪保值品牌榜,当贝投影闲鱼保值率排行TOP1

How can non-standard automation equipment manufacturing enterprises achieve rapid and accurate quotation with the help of ERP system?

Construction of specflow environment

Security mechanism of verification code in seckill

Mctalk's entrepreneurial voice - erudition and discernment: be interested in socializing, and provide a "small and beautiful" space for old friends before and after retirement
随机推荐
Adobe Premiere foundation - batch material import sequence - variable speed and rewind (recall) - continuous action shot switching - subtitle requirements (13)
Redis data type daily use scenarios
What problems should be paid attention to in running health preserving physiotherapy center?
4、LockSupport与线程中断
ASCII, Unicode, and UTF-8
Problems encountered recently when using nodejs Pinyin package
Jerry's aicmd_ SET_ BT_ Addr command format [chapter]
Usage of instr function in Oracle Database
Splunk manually synchronize search head
11. Synchronized and lock escalation
Oracle database import data steps
4K投影儀哪款性價比最高,當貝X3 Pro高亮128G存儲618值得看
Another way to achieve family reunion, 2022 flagship projection nut j10s is planted with grass
oracle数据库导入数据步骤
Mctalk's entrepreneurial voice - erudition and discernment: be interested in socializing, and provide a "small and beautiful" space for old friends before and after retirement
C# System. Guid. Newguid() format
综合场馆的优势有哪些?
科海融生&正航,以信息化驱动管理升级,携手共迎数智未来
CMD of Jerry's AI protocol_ SET_ BLE_ Format of visibility command [chapter]
非标自动化设备制造企业,如何借助ERP系统实现快速精准报价?