当前位置:网站首页>【秒杀概念】原反补
【秒杀概念】原反补
2022-07-26 00:43:00 【粉墨白伶】
目录
秒杀概念,编程如此简单!快点击订阅吧!
正数
正数的原、反、补码都相同
负数
原码
直接将数字按照正负数的形式翻译成二进制就可以
反码
将原码的符号位不变,其他位依次按位取反就可以得到了
补码
反码+1就得到补码
对于整形来说:数据在内存中的形式其实就是补码
在计算机系统中,整型类型的数值一律用补码来表示和存储
因为用补码相加可以实现减法,所以 CPU 可以不需要专门去实现减法器,降低了硬件成本
而且补码的补码就是原码,因此 CPU 只需要实现补码器和加法器即可实现整数的加减乘除
乘法就是多加几次,除法就是能减几次,当要输出负数时就将内存中的补码转为源码再输出
减法示例:
1 - 1 = 1 + (-1)由于 int 类型的大小为 8 个字节,1 个字节 8 个比特位,所以一共有 32 个比特位
1 :
1 的源码为
0000 0000 0000 0000 0000 0000 0000 0001
1 的反码为
0000 0000 0000 0000 0000 0000 0000 0001
1 的补码为
0000 0000 0000 0000 0000 0000 0000 0001
-1:
-1 的源码为
1000 0000 0000 0000 0000 0000 0000 0001
-1 的反码为
1111 1111 1111 1111 1111 1111 1111 1110
-1 的补码为
1111 1111 1111 1111 1111 1111 1111 1111
补码相加等于
(1) 0000 0000 0000 0000 0000 0000 0000 0000
前面括号中的 1 超出了 4 个字节 32 个比特位,所以被丢失了,因此 1 + (-1) 的结果为 0
边栏推荐
- Hnoi2012 mine construction
- With data-driven management transformation, the first year of science and technology was at the right time
- [install software after computer reset] software that can search all files of the computer, the best screenshot software in the world, free music player, JDK installation, MySQL installation, installa
- ASP. Net core configuration
- [RTOS training camp] review of the previous section, idle tasks, timer tasks, execution sequence, scheduling strategy and evening class questions
- [RTOS training camp] equipment subsystem, questions of evening students
- HCIP第十二天
- The task will be launched before the joint commissioning of development
- 如何mysql只要重复数据?
- 200 yuan a hair dryer, only a week, to achieve 2million?
猜你喜欢

分布式事务和Seata的AT模式原理
![[RTOS training camp] task scheduling (Continued), task comity, scheduling summary, queue and evening class questions](/img/0f/ca576a2f90aba4ddbb1f8b3e8a8ced.jpg)
[RTOS training camp] task scheduling (Continued), task comity, scheduling summary, queue and evening class questions

【RTOS训练营】课程学习方法和结构体知识复习 + 链表知识

进程与线程
![[laser principle and application -3]: foreign brands of lasers](/img/8a/620544bb52c6b8c4db83f9a14783bb.png)
[laser principle and application -3]: foreign brands of lasers

The task will be launched before the joint commissioning of development

With data-driven management transformation, the first year of science and technology was at the right time

南姐的糗事

Download exclusively | Alibaba cloud maxcompute questions and answers to unlock SaaS mode cloud data warehouse in this electronic manual!
![[RTOS training camp] GPIO knowledge and preview arrangement + evening class questions](/img/44/f3323a16e505a7fe923b25630f62f7.jpg)
[RTOS training camp] GPIO knowledge and preview arrangement + evening class questions
随机推荐
ZABBIX monitoring host and resource alarm
Lock upgrade: no lock, bias lock, lightweight lock, heavyweight lock
How can a team making facial mask achieve a revenue of more than 1 million a day?
Unity get the animation being played
Hcip day 11
[oops framework] random number generation management
MMOCR使用指南
JDBC实现MySQL8.0数据库的增删改查
Talk about "people" in the R & D team
Openvino installation pit notes
[RTOS training camp] program framework, preview, after-school homework and evening class questions
We have no way out
BGP comprehensive experiment
The difference between TCP and UDP
Travel + strategy accelerated landing, jietu new product matrix exposure
我们没有退路了
开放下载!《阿里巴巴 DevOps 实践手册》
Hnoi2012 mine construction
The task will be launched before the joint commissioning of development
独家下载|《阿里云MaxCompute百问百答》 解锁SaaS模式云数据仓库尽在本电子手册!