当前位置:网站首页>C language - vernacular to understand the original code, inverse code and complement code
C language - vernacular to understand the original code, inverse code and complement code
2022-08-05 04:21:00 【Pointer to a PI】
Thank you for reading
Learning Catalog
Original, Inverse and Complement
1. Understand storage types
- Data is divided into byte type and word type data
Byte type data occupies 8 bits, its original code, inverse code and complement code are all 8 bits, indicating 0-255
Font type data occupies 8 bits16 bits, its original code, inverse code and complement code are all 16 bits, which means 0-65535 - Then some people will have doubts: 8-bit binary and 16-bit binary are both 1. Of course, it can represent 255 or 65535, but I can also represent -127, -32767.Now that we say that, do we have to figure out what storage method is, whether it is unsigned storage or signed storage?
- In 8 bits, if it is unsigned storage - that is, 0-255 has no negative number, if it is a signed number, it will occupy one bit by itself, so it is represented as -127-128.
So I know that our C language int type is also a signed number when it is not written unsigned, its range is -2147483648~+2147483647, and the signed number is 4,294,967,295 - So what is the source code stored?Are we talking about the original code, whether it is signed or unsigned?It is very responsible to tell you that this is a signed code, so we look at the original code of 8 digits or the original code of 16 digits, and we can see whether it is positive or negative at a glance
2. Original code, inverse code, complement code
1. Throwing out the concept of three codes
Original code: the highest bit is the sign bit, 0 represents a positive number, 1 represents a negative number, and the others are 0 or 1.Inverse code: The inverse code of a positive number is consistent with the original code, and the inverse code of a negative number is the inverse of the original code, and the sign bit remains unchanged.Complement code: The complement code of a positive number is the same as the original code, and the complement code of a negative number is to invert the original code and add 1, and the sign bit remains unchanged.Example00000001 (Decimal from the original code is 1)Example 10000001 (The decimal derived from the original code is -1??)So is it?00000001+ 10000001------------100000101+(-1) = -2??Outrageous!!!! - But I tell you responsibly, this is -1, but if you count it directly, it's definitely not like this.To perform binary addition and subtraction, it finally becomes addition.
Do we have a question, the computer -1+1 is not equal to 0 directly, so what should the computer do, how can it be equal to 0? - We want to find out 1+(-1)=0 and make it true, then we assume that -1 has a substitute, which is an eight-digit unknown x
00000001+ xxxxxxxx------------00000000- It can be obtained that if 11111111 is added to 1 and becomes 100000000, it will cause a bit overflow and lose the highest bit 1, so isn't this a decimal 0?So I'm sure that adding (-1) equals 0, that is, adding his substitute, he is 111111111
- It turned out to be like this, except for the highest bit, I invert all of them and then +1
This is also the case, the concept of complement code is also the same, that is, the original code except the highest bit is inverted and then +1, however his positive calculation process is
Example 10000001 original codeIf you want to change the complement code, you can change the inverse code before you can , inverse bit by bit, except for the sign bit of the highest bitExample 11111110 inverse codeTo change to complement code, just add 1 after the inverse code.Example 11111111 complement (original code except the highest bit is inverted and then +1)So, in a sense, this becomes 1 + (-127) = 0, but don't confuse it, it will be stressful to understand
We still understand it honestly: for calculationBoth are calculated as the complement of positive or negative numbers.
2. Final summary
The purpose of introducing the inverse code and the complement code of the original code is to solve the problem of subtraction, because there is only an adder in the arithmetic unit of the computer CPU, and the subtraction must be converted into an addition for calculation.
3. To Readers
Thank you for reading
边栏推荐
- pyqt5 + socket 实现客户端A经socket服务器中转后主动向客户端B发送文件
- [MRCTF2020]Ezpop(详解)
- Use IDEA to connect to TDengine server
- 多列属性column元素的可见性:display、visibility、opacity、垂直对齐方式:vertical-align、z-index 越大越显示在上层
- 4T硬盘剩余很多提示“No space left on device“磁盘空间不足
- [MRCTF2020] PYWebsite
- Mysql's redo log detailed explanation
- A 35-year-old software testing engineer with a monthly salary of less than 2W, resigns and is afraid of not finding a job, what should he do?
- How do newcomers get started and learn software testing?
- 使用IDEA连接TDengine服务器
猜你喜欢
![[极客大挑战 2019]FinalSQL](/img/e4/0c8225ef7c5e7e5bdbaac2ef6fc867.png)
[极客大挑战 2019]FinalSQL

Mysql的redo log详解

bytebuffer 使用demo

35岁的软件测试工程师,月薪不足2W,辞职又怕找不到工作,该何去何从?

About the installation of sklearn library

浅析主流跨端技术方案

开发属于自己的node包
![【 8.4 】 source code - [math] [calendar] [delete library 】 【 is not a simple sequence (Bonus) 】](/img/b5/716627b370e489ccf320a86540f7ba.png)
【 8.4 】 source code - [math] [calendar] [delete library 】 【 is not a simple sequence (Bonus) 】

UE4 第一人称角色模板 添加生命值和调试伤害

【8.1】代码源 - 【第二大数字和】【石子游戏 III】【平衡二叉树】
随机推荐
App rapid development and construction experience: the importance of small programs + custom plug-ins
How to solve the three major problems of bank data collection, data supplementary recording and index management?
Please write the SparkSQL statement
How do newcomers get started and learn software testing?
【背包九讲——01背包问题】
工业级远距离无线传输装置的功能有哪些?
UE4 第一人称角色模板 添加蹲伏功能
MySql index learning and use; (I think it is detailed enough)
BI业务分析思维:现金流量风控分析(二)信用、流动和投资风险
【informix】解决启动报错大全,以及解决办法
【 8.4 】 source code - [math] [calendar] [delete library 】 【 is not a simple sequence (Bonus) 】
Day14 jenkins deployment
In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit
UE4 第一人称角色模板 添加冲刺(加速)功能
Index Mysql in order to optimize paper 02 】 【 10 kinds of circumstances and the principle of failure
第一次性能测试实践,有“亿”点点紧张
如何解决复杂的分销分账问题?
[BJDCTF2020] EasySearch
NPDP证书含金量高吗?跟PMP相比?
关于sklearn库的安装