当前位置:网站首页>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 !
边栏推荐
- 如何利用 xUnit 框架对测试用例进行维护?
- torch stack() meshgrid()
- Nodejs 安装与介绍
- 期货怎么开户安全些?现在哪些期货公司靠谱些?
- Pyth Solana is a bridge connecting reality on the chain
- Where do the guests come from
- 链表中环的入口结点-链表专题
- 「经验」爬虫在工作中的实战应用『理论篇』
- How to use the low code platform of the Internet of things for service management?
- Word -- a solution for word to encounter errors when trying to open a file
猜你喜欢

20220607跌破建议零售价,GPU市场正全面走向供过于求...

Ansi/ul 94 class 5-V vertical combustion test

简述机器学习中的特征工程

传统微服务框架如何无缝过渡到服务网格 ASM

Nodejs installation and introduction

Kalman filter -- Derivation from Gaussian fusion

German agbb VOC hazardous substances test

dtd建模

VMware16安装Win11虚拟机(最全步骤+踩坑)

BeanUtils.copyProperties() 对比 mapstruct
随机推荐
拓維信息使用 Rainbond 的雲原生落地實踐
ros advertise 发布数据小技巧--latch配置
torch. roll
开发那些事儿:如何在视频中添加文字水印?
如何使用物联网低代码平台进行服务管理?
浏览器窗口切换激活事件 visibilitychange
mysql修改数据类型_MySQL修改字段类型[通俗易懂]
Rust 如何实现依赖注入?
虚拟主机什么时候适合更换成云主机?
How to use the low code platform of the Internet of things for service management?
CTF流量分析常见题型(二)-USB流量
Nodejs 安装与介绍
基于UDP协议设计的大文件传输软件
JS 如何正确清除一个元素下的所有子元素
Where do the guests come from
Nodejs installation and introduction
联想YOGA 27 2022,超强配置全面升级
MySQL download and installation tutorial
3.10 haas506 2.0 development tutorial example TFT
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)