当前位置:网站首页>1.3 - 码制
1.3 - 码制
2022-06-30 06:12:00 【是李黏黏鸭】
目录
一、机器数
1、计算机采用的数值的表达方式就是机器数;
- 在生活中我们是按十进制计数的,例如10;但是在计算机中是用二进制,这个用于表示十进制数10的二进制的0、1序列,就是机器数。
2、计算机对机器数的约定
- 计算机中约定固定长度的二进制位来表示一个数;
- 机器数中约定,用最高为来表示一个数的正负;
- 计算机中约定,小数点的位置是固定的;所以机器数中,不需要一位专门的二进制位来表示这个数是小数;
3、举例说明
- 1对应的机器数是:0(符号位)0000001;
- -1对应的机器数是:1(符号位)0000001;
- 整数时的小数点位置:0(符号位)0000000.0;
- 小数时的小数点位置:0(符号位).0000000;
二、码制
1、原码
- 原码(true form)是计算机中一种对数字的二进制定点表示方法。
- 可理解为直接由十进制数转换得到的二进制数,就是原码;
- 由图可知,使用原码来进行二进制数的加减法运算,所得到的结果是错误的;原因是,计算时对原码中的符号位也进行了运算;

- 将原码中的符号位剔除出来;
- 然后确认减数和被减数的大小,依此来判断计算结果是整数还是负数;
- 然后再进行运算。
2、反码
- 按照原码的逻辑进行运算,就复杂了,不利于计算机的实现,所以对于机器数的运算又想出了其他编码方式-反码。
- 正数的原码转反码:不变;
- 负数的原码转反码: 符号位不变;数值位按位取反;

- 由图可知,使用反码来进行二进制数的加减法运算,所得到的结果是错误的;原因也是,计算时对原码中的符号位也进行了运算;
3、补码
- 按照反码的逻辑进行运算,就复杂了,不利于计算机的实现,所以对于机器数的运算又想出了其他编码方式-补码。
- 正数的原码转补码:不变;
- 负数的原码转补码: 符号位不变;数值位按位取反后+1;

- 整数的补码=反码;
- 负数的补码= 反码+1;
- 由图可知,使用补码来进行二进制数的加减法运算,所得到的结果是正确的;
- 用于二进制的加减运算;
4、移码
- 通过补码表示浮点数时,可能会出现问题;例如
当n无限趋于0的时候,
就等于
,就是不正确的;所以用移码来表示浮点数;
- 正数的移码=补码的符号位取反,其他位不变;
- 负数的移码=补码的符号位取反,其他位不变;

- 移码常用于表示浮点数中的阶码。而浮点数的阶码主要决定了浮点数能表示的数值范围。
三、数表示的范围

1、原码
- n位二进制对应的表示编码的个数的计算公式:
; - n-1:最高位是符号位,只表示数值的正负,不表示数值的大小;表示数值位的二进制位数少了一位,所以需要减去1;
:n位二进制数值,表示的编码个数;
:编码时从0开始编,0~3是四个编码;
是四个编码,分别是00、01、10、11,其中最大值是3;所以
需要再减去1才是最大编码值;所以2n-1-1才能得到最大编码值,才能得到数表示的最大范围; - 又因为原码的最高位是符号位,说明原码可正可负,所以原码表示的范围有负区间;
2、反码
- 与原码表示的范围一致;
3、补码
- 补码表示的范围的正区间,与原码和反码一致;
- 补码的负区间没有减一,原因是
4、移码
- 与补码表示的范围一致;
四、考法:数的表示范围


五、各种码制的特点、应用场景

边栏推荐
- Unable to access the Internet at win10 /11 hotspot
- [regular expression series] greedy and non greedy patterns
- Base64详解:玩转图片Base64编码
- C language final experiment report (student achievement management system) source code
- Ten years' miscellaneous thoughts
- Traitement d'images 7 - amélioration d'images
- Strlen and sizeof, array length and string length, don't be silly
- DXP copper laying settings
- 【学习强化学习】总目录
- Completabilefuture: from understanding to mastering, here are all you want to know
猜你喜欢

关注这场直播,了解能源行业双碳目标实现路径

DHCP operation

01. 正则表达式概述

01. regular expression overview

Installation and initialization of MariaDB database

Using C language pure for loop to implement ilovey

Common NPM install errors

1.8 - 多级存储
![[wechat applet: single or multiple styles, background color, rounded corners]](/img/01/0381915591b0d3c13afbba4d50952d.png)
[wechat applet: single or multiple styles, background color, rounded corners]

Summation of basic exercise sequence of test questions
随机推荐
多线程进阶篇
Basic use of markdown
Installing googleplay environment on Huawei mobile phones
Centos8 install redis
Loading class `com. mysql. jdbc. Driver‘. This is deprecated. The new driver class is `com. mysql. cj. jdb
How to use unmarshaljson
Vscode configuration proxy
Suggestion: use tools:overrideLibrary
重构之美:当多线程批处理任务挑起大梁 - 万能脚手架
Beauty of Refactoring: when multithreaded batch processing task lifts the beam - Universal scaffold
一个完整的性能测试流程
A small template (an abstract class, a complete process is written in a method, the uncertain part is written in the abstract method, and then the subclass inherits the abstract class, and the subclas
Installation and initialization of MariaDB database
Spin official tutorial
SparseArray
Common address collection
Is it safe to open an account online? Can you open an account to speculate on the Internet?
PHP knowledge points
Gazebo installation, uninstall and upgrade
Summary of 2 billion redis data migration