信息与编码,二进制数补码的本质

编程入门 行业动态 更新时间:2024-10-06 01:41:24

信息与编码,二进制数<a href=https://www.elefans.com/category/jswz/34/1728340.html style=补码的本质"/>

信息与编码,二进制数补码的本质

  • what is “information”

Information resolves uncertainty. Information is simply that which cannot be predicted. The less predictable a message is, the more information it conveyed.

信息消除不确定性,一条消息越不可预测,传递的信息越多。

  • 度量信息(Quantifying Information)

Suppose you’re faced with N equally probable choices, I give you a fact that narrows it down to M choices. Then I give you log2(N/M) bits information. (Claude Shannon, 1948)

概率相等地面对N中可能,一个事实将其降为M种可能,该事实包含了log2(N/M) 位的信息。

例子:
one coin flip: log2(2/1) = 1 bit
roll of 2 dice: log2(36/1) = 5.2 bits

  • 编码(Encoding)

Encoding describes the process of assigning representations to information.

Choosing an approciate and efficient encoding is a real engineering challenge.

Impacts design at many levels: Mechaism (devices, # of components used), Efficient (bits), Reliable (noise), Security (encryption)

  • 数的编码(Encoding numbers)

数制:表示数量的规则,由“位 + 进位规则”构成
码制:表示事物的规则

数制的编码,无论是二进制、十进制、十六进制等所有进制,都是各位上数值与权重(weight)的积的和。十进制“100”是编码,之所以表示“100”,是 1∗102 1 ∗ 10 2

  • 二进制数的补码(2’s complement)

最高位为符号位 (0为正,1为负)
正数的补码与原码相同
负数的补码 = 原码逐位求反(反码) + 1

二进制数的补码的问题:
符号位是码制,并不代表数值,不能进行加法运算。补码的本质是给符号位赋予权重,使其表示数值。

8-bit 2’s complement example:

11010110 = −27+26+24+21 − 2 7 + 2 6 + 2 4 + 2 1 = -128 + 64 + 16 + 4 + 2 = -42

By moving the implicit location of “decimal” point, we can represent fractions too:

1101.0110 = −23+22+20+2−2+2−3 − 2 3 + 2 2 + 2 0 + 2 − 2 + 2 − 3 = -8 + 4 + 1 + 0.25 + 0.125 = -2.625

4和-4的补码表示

0100 = 0 0100 = 00 0100
100 = 1100 = 1 1100 = 11 1100

  • 补码表示的二进制数相加的符号位

13 + 10、13 - 10、 -13 + 10 、 -13-10

// 考虑进位问题,需要6位0/1表示
// 13 + 10 = 23
0 01101 + 0 01010 = 0 10111// -13 + 10 = -3
1 10011 + 0 01010 = 1 11101// -13 - 10 = -23
1 10011 + 1 10110 = 1 01001
// 两个加数的符号位和来自最高位数字位的进位相加,结果就是和的符号。符号位溢出后舍弃。

参考:
:TsinghuaX+20250103X+sp+type@asset+block/First_Chapter_PPT.pdf
.html

更多推荐

信息与编码,二进制数补码的本质

本文发布于:2024-02-14 13:39:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1763500.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:补码   本质   二进制数   信息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!