当前位置:网站首页>有关原码,反码,补码那些事
有关原码,反码,补码那些事
2022-08-07 23:35:00 【51CTO】
我学c语言时,刚遇到原码,反码,补码,那可搞的我花了不少时间才弄懂,我为了让更少人走弯路,
讲讲我的理解吧。
1.要知道原码:原码就是符号位加上真值的绝对值,即用第一位表示符号,其余位表示值比如:如果是8位二进制:+1原码= 0000 0001 正数的符号位是0
-1原码= 1000 0001 负数的符号位是1
2.要知道十进制转化位二进制的方法
整数除二取余,先得到的余数从低位排起,直到商为0.小数乘二取整,也是从低位排起。
如2的原码= 0000 0010
0.2原码= 0.001(看要求取多少位)
3.要知道为什么不能只用原码不用反码或补码呢?
为了解决原码做减法的问题, 出现了反码如计算十进制的表达式: 1 - 1 = 0
1 - 1 = 1 + (-1) = [0000 0001]原+ [1000 0001]原= [1000 0010]原= -2
显然不正确
同样为了解决1 - 1 = 1 + (-1) = [0000 0001]原+ [1000 0001]原= [0000 0001]反+ [1111 1110]反= [1111 1111]反= [1000 0000]原= -0 ,虽然人们理解上+0和-0是一样的,但是0带符号是没有任何意义的,而且会有[0000 0000]原和[1000 0000]原两个编码表示0所以出现了补码。
4.要知道它们的关系
原码--- 反码 --- 补码
//按位取反 +1
//补码--- 反码 --- 原码
// —1 按位取反
5.要知道计算机的原理

边栏推荐
- 【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)
- MYSQL高级篇-----索引优化分析
- kylin-desktop日志文件功能说明
- 【UiPath2022+C#】UiPath 练习-Excel和数据表
- 银行科技岗面试
- c语言入门---自定义类型:结构体,枚举,联合
- Google and universities released the end-to-end panoramic segmentation method MaX-DeepLab, which greatly reduces the artifacts of image segmentation and does not contain manual modules
- Shell脚本,打包文件压缩到指定目录,每天定时任务运行脚本
- MPLS网络向SRv6网络演进
- MySQL notes - 05 data table operations
猜你喜欢

Expansion of the Unity editor - Scene view custom operations

现代企业架构框架 — 业务架构

C语言:打印水仙花数

Unity editor extension--custom shortcut key extension

c语言入门---自定义类型:结构体,枚举,联合

【云原生--Kubernetes】PV、PVC

Force buckle 206, reverse linked list

solidworls view and model and drawing operation shortcuts

Google and universities released the end-to-end panoramic segmentation method MaX-DeepLab, which greatly reduces the artifacts of image segmentation and does not contain manual modules

D. Tournament Countdown(交互题)
随机推荐
记一个Thinkphp3老项目 设置模板多重继承
我做了一个在线白板(二)
@Transactional指定回滚条件
pinia详解
扁平路由匹配多级面包屑思路总结
uniapp pages.json 简单应用
阿里云云原生数据湖体系全面解读
The generation process of Presto Stage
[Students' personal web design works] Use HMTL to make a super beautiful web page for protecting dolphins
测试也应该具备的项目管理能力
继承关系下构造方法的访问特点
你知道网络安全领域中有哪些常用的抓包工具吗?(附资料)
将一句话的单词进行倒置,标点不倒置。
D. Chip Move(DP,优化时间和空间)
buu web部分wp
win10安装pycuda2022
2022-08-07:以下go语言代码输出什么?A:1 1;B:3 1;C:0 3;D:不能编译。 package main import ( “fmt“ “math“ ) func main
flink
Unity editor extension -- Hierarchy extension
doc或docx(word)或image类型文件批量转PDF脚本