当前位置:网站首页>Small notes - integer improvement (C language)
Small notes - integer improvement (C language)
2022-06-30 19:24:00 【Wind blown electric fan】
Improve the overall shape
Write it at the front
Finally, the training in the school has been completed , Now start the normal update .
Hello everyone , Here are the fan's little notes , This note briefly records the concept of plastic enhancement 、 Meaning and simple examples , Thank you for your support .
Plastic surgery improves
- Shaping lifting concept
C The integer arithmetic operation of always takes at least the default integer type (int) The accuracy of . In order to achieve this precision , The character type and short integer operands in the expression are converted to normal integers before use , This conversion is called integer
promote .
- Plastic surgery improves the meaning
The integer operation of expression should be in CPU In the corresponding computing device of ,CPU Inner integer arithmetic unit (ALU) The byte length of the operands of
It is commonly int Byte length of , It's also CPU The length of the general register of .
therefore , Even two char The addition of types , stay CPU When executing, it should be converted to CPU The standard length of an inner integer operand
degree .
Universal CPU(general-purpose CPU) It is difficult to realize two directly 8 Direct addition of bits and bytes ( Although machine instructions
There may be such byte addition instructions in ). therefore , Various lengths in expressions may be less than int The integer value of the length , You have to turn first
Replace with int or unsigned int, Then it can be sent in CPU To perform the operation .
- Shaping promotion rules
️ The high-order supplementary sign bit during the lifting of the integer , Unsigned types are high complement 0.
- Example :
With int The type and unsigned int Type to print char Type data process
int main()
{
char a = -128;
//char Range -128—127
printf("%d %u",a, a);
return 0;
}
Running results :
a The storage process of the value of :
10000000 00000000 00000000 10000000 -128 The original code of
Reverse the original code
11111111 11111111 11111111 01111111 -128 The inverse of
One plus one
11111111 11111111 11111111 10000000 -128 Complement
a Length bit 1 byte a:10000000 Complement truncation , Take the last byte
Take out a Value :
10000000 a
11111111 11111111 11111111 10000000 a Plastic surgery improves
The complement minus one
11111111 11111111 11111111 01111111 After promotion a The inverse of
The sign bits remain the same , Reverse other bits
10000000 00000000 00000000 10000000 After promotion a The original code of
With int Form printing a, The highest bit is the sign bit
The value printed is -128
With unsigned int Form printing : The highest bit is not a sign bit
The value printed is 4294967168
Last
To get the whole content of this note , Original code 、 The inverse code and complement code were discussed in the last article, so this time we will talk about them roughly .
Finally, thank you for your support to the small fan , Work together !
边栏推荐
猜你喜欢

Year after year, why is breaking the data island still the primary task of enterprise development

Pyth-Solana链上联通现实的桥梁

20220607 fell below the recommended retail price, and the GPU market is moving towards oversupply

拓维信息使用 Rainbond 的云原生落地实践

Four tips tell you how to use SMS to promote business sales?

Browser window switch activation event visibilitychange

微信小程序快速入门 --项目介绍

Entry node of link in linked list - linked list topic

Lenovo Yoga 27 2022, full upgrade of super configuration

Swin-transformer --relative positional Bias
随机推荐
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)
Regular expressions (regular matching)
Practical application of "experience" crawler in work "theory"
[community star selection] the 23rd issue of the July revision plan | bit by bit creation, converging into a tower! Huawei freebuses 4E and other cool gifts
如何使用物联网低代码平台进行服务管理?
torch stack() meshgrid()
opencv数据类型代码表 dtype
mysql中union和union all的区别
如何利用 xUnit 框架对测试用例进行维护?
Large file transfer software based on UDP protocol
德国AgBB VoC有害物质测试
Development: how to install offline MySQL in Linux system?
美国服务器租用和托管服务哪个好?
20220607 fell below the recommended retail price, and the GPU market is moving towards oversupply
Delete duplicate elements in the sorting linked list ii[unified operation of linked list nodes --dummyhead]
Reading notes of "high EQ means being able to talk"
JS 如何正确清除一个元素下的所有子元素
Memory Limit Exceeded
20200525-生物技术-四川师范大学自考生物技术(本科)考试计划.txt
Go Redis连接池