当前位置:网站首页>【秒杀概念】原反补
【秒杀概念】原反补
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
边栏推荐
- Test the concept of left shift and right shift
- [array creation in numpy]
- Leetcode notes 20. valid parentheses
- Biological JC uvssa complex alleviates myc driven transcription pressure ⼒ English
- Master MySQL in an article
- Getting started with D3D calculation shaders
- 嵌入式开发:技巧和窍门——设计强大的引导加载程序的7个技巧
- The ultra comprehensive open source WinForm UI library meets all your desktop development needs!
- Lock upgrade: no lock, bias lock, lightweight lock, heavyweight lock
- [RTOS training camp] task scheduling (Continued), task comity, scheduling summary, queue and evening class questions
猜你喜欢

分布式事务和Seata的AT模式原理

Curd used by hyperf

【RTOS训练营】关于上课和答疑

【RTOS训练营】环形缓冲区、AT指令、预习安排和晚课提问

【RTOS训练营】上节回顾、空闲任务、定时器任务、执行顺序、调度策略和晚课提问

JDBC implements the addition, deletion, modification and query of MySQL 8.0 database

【RTOS训练营】任务调度(续)、任务礼让、调度总结、队列和晚课提问

Zabbix监控主机及资源告警

超全的开源Winform UI库,满足你的一切桌面开发需求!

【MATLAB appdesigner】27_ How to debug and view variables in appdesigner? (examples + skills)
随机推荐
进程与线程
Hcip day 12
超全的开源Winform UI库,满足你的一切桌面开发需求!
ZABBIX monitoring host and resource alarm
[translation paper] analysis of land cover classification using multi wavelength lidar system (2017)
JDBC implements the addition, deletion, modification and query of MySQL 8.0 database
【RTOS训练营】程序框架、预习、课后作业和晚课提问
数据写入excel并填充颜色
HCIP 第十一天
HCIP第十二天
[RTOS training camp] program framework, preview, after-school homework and evening class questions
BGP 综合实验
Lock upgrade: no lock, bias lock, lightweight lock, heavyweight lock
什么是信息化?什么是数字化?这两者有什么联系和区别?
Selenium assertion and JS actuator
[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
C language_ The use and implementation of string comparison function StrCmp
Unityvr robot Scene 3 gripper
Leetcode notes 20. valid parentheses
Unity get the animation being played