📝 我的笔记

还没有笔记

选中页面文字后点击「高亮」按钮添加

Lec01-Numbers-260122打印.ZH段落

📜 原文
📖 逐步解释
∑ 公式拆解
💡 数值示例
⚠️ 易错点
📝 总结
🎯 存在目的
🧠 直觉心智模型
💭 直观想象

1CSEE 3827:计算机系统基础(2026 年春季学期)

1. 第 1 讲

授课教师Dan Rubenstein 教授

电子邮箱danr@cs.columbia.edu

1Ch1. 快速公告 Quick Announcements P1

2Ch2. 关于讲义的说明 A note on lecture slides P2

3Ch3. 议程 (M&K 章节 1, 3.11, 9.7) Agenda P3

4Ch4. 课程概述:构建计算机(数字视角) Course Overview: Building a computer (digital perspective) P4

1Ch4.1. 课程概述:第一季度 Course Overview: 1st quarter P5

2Ch4.2. 课程概述:第二季度 Course Overview: 2nd quarter P6

3Ch4.3. 课程概述:后半部分 Course Overview: 2nd Half P7

计算机处理程序(存储在内存中)

本学期稍后详细介绍...

到五月...

到五月...

到五月...

5Ch5. 不同进制的加法 Addition in different bases P8

1Ch5.1. 数制回顾:10 进制 (十进制) Number systems review: Base 10 (Decimal) P9

$$ \begin{array}{cccc} 4 & 5 & 3 & 7 \\ \times 10^{3} & \times 10^{2} \\ \hline 4000 & \times 10^{1} & \times 10^{0} & \times 10^{-1} \\ 500 & \times 30 & +7 & +8=4537.8 \end{array} $$

1. 数制回顾:10 进制 (十进制) Number systems review: Base 10 (Decimal) P10

$$ \begin{array}{cccc} 4 & 5 & 3 & 7 \\ \times 10^{3} & \times 10^{2} \\ \hline 4000 & \times 10^{1} & \times 10^{0} & \times 10^{-1} \\ 500 & +30 & +7 & +8=4537.8 \end{array} $$

$$ \begin{gathered} 1 \\ \times 2^{3} \times 2^{2} \times \frac{1}{1} \times 2^{1} \times 2^{0} \times \frac{\times 2^{-1}}{8}+\frac{1}{2}=(11.5)_{10} \end{gathered} $$

2Ch5.2. 数制:2 进制 (二进制) Number systems: Base 2 (Binary) P11

$$ \begin{gathered} 1 \\ \times 2^{3} \times 2^{2} \times \frac{1}{1} \times 2^{1} \times 2^{0} \times \frac{\times 2^{-1}}{8}+\frac{1}{2}=(11.5)_{10} \end{gathered} $$

将一向左会使数字乘以 2

3Ch5.3. 数制:16 进制 (十六进制) Number systems: Base 16 (Hexadecimal) P12

基数 16 (十六进制) 基数 2 (二进制) 基数 10
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
A 1010 10
B 1011 11
C 1100 12
D 1101 13
E 1110 14
F 1111 15

1. 数制:16 进制 (十六进制) Number systems: Base 16 (Hexadecimal) P13

$$ \begin{array}{cccc} 2 & 6 & \text { B } & \text { A } \\ \times 16^{3} & \times 16^{2} \\ \hline 8192 & \times 16^{1} & \times 16^{0} \\ & =(9914)_{10} \end{array} $$

2 6 B A
$\times 16^{3}$ $\times 16^{2}$ $\times 16^{1}$ $\times 16^{0}$

$$ 8192+1536+176+10=(9914)_{10} $$

6Ch6. 数字范围 Number ranges P14

...5 个十进制数字$10^{5}$ 可能值 $(100,000)_{10}$

...8 个二进制数字$2^{8}$ 可能值 $(256)_{10}$

...4 个十六进制数字$16^{4}$ 可能值 $(65,536)_{10}$

7Ch7. 为什么基数 16 (十六进制) 有用 Why Base 16 (Hexadecimal) is useful P15

1Ch7.1. 为什么基数 16 (十六进制) 有用(续) Why Base 16 (Hexadecimal) is useful (cont'd) P16

$$ \begin{aligned} & =2^{4} \cdot\left(1 \cdot 2^{3}+0 \cdot 2^{2}+1 \cdot 2^{1}+0 \cdot 2^{0}\right) \\ & =16^{1}{ }_{(10)} \cdot 10_{(10)} \\ & =10_{(\mathrm{Hex})} \cdot A_{(\mathrm{Hex})}(A \text { in 2nd column }) \end{aligned} $$

26 B A

2Ch7.2. 使用基数 16 Using Base 16 P17

8Ch8. 定义 & 术语 Defs & Terminology P18

1Ch8.1. 从数字视角看计算机 Computer from Digital Perspective P19

. 即,$(16(1)+8(0)+4(0)+2(1)+1(1))$ 在二进制

[10 进制]

[二进制]

2Ch8.2. 术语 2:最高/最低位/有效位 Terminology 2: Highest / Lowest Order / significant bits P20

9Ch9. 模运算 Modular Arithmetic P21

1Ch9.1. 定义与基本示例 Definition & Basic Examples P22

风车表示法对正数顺时针移动

对负数逆时针移动

这个风车是用于 $\bmod 8$

2Ch9.2. 负数模运算与风车表示法 Negative Modular Arithmetic & Pinwheel P23

风车表示法对正数顺时针移动对负数逆时针移动

这个风车是用于 $\bmod 8$

3Ch9.3. 模运算性质与更多示例 Properties & More Examples P24

$22 \bmod 5=2$

$22=5 * 4+2)$

风车表示法对正数顺时针移动对负数逆时针移动

这个风车是用于 $\bmod 8$

10Ch10. 带负数表示的模运算 Modular Arithmetic with negative representations P25

风车表示法对正数顺时针移动

对负数逆时针移动

风车表示法对正数顺时针移动对负数逆时针移动

这个风车是用于 $\bmod 8$范围 $\mathbf{- 4}$$\mathbf{3}$

2 的补码很重要稍后讨论

1Ch10.1. 替代余数定义(负范围) Alternative Remainder Definition (Negative Range) P26

风车表示法对正数顺时针移动对负数逆时针移动

这个风车是用于 $\bmod 8$范围 -4 到 3 )

2 的补码很重要稍后讨论

2Ch10.2. 负范围模运算示例 Negative Range Modular Arithmetic Examples P27

风车表示法对正数顺时针移动对负数逆时针移动

这个风车是用于 $\bmod 8$范围 -4 到 3 )

2 的补码很重要稍后讨论

3Ch10.3. 更多负范围示例与补码关联 More Examples & Complement Connection P28

风车表示法对正数顺时针移动

对负数逆时针移动

这个风车是用于 $\bmod 8$范围 $\mathbf{- 4}$$\mathbf{3}$

2 的补码很重要稍后讨论

11Ch11. 整数 # 格式(带字长限制) Integer # Formats (with word size restriction) P29

假设 字长 $=k$(例如, $k=3$

具有 字长 $k$

假设 字长 $=k$(例如, $k=3$

具有 字长 $k$

000 15
001 -7
010 42
011 42
100 7
101 9
110 $\mathrm{e}^{7}$
111 0.004

12Ch12. 二进制加法算法(无符号数) Binary Addition Algorithm (of unsigned numbers) P30

$$ \begin{array}{r} 11110 \\ +\quad 10101 \\ \hline \end{array} $$

1Ch12.1. 二进制加法算法(无符号数) Binary Addition Algorithm (of unsigned numbers) P31

2Ch12.2. 模运算和溢出 Modular Arithmetic and Overflow P32

$$ \begin{array}{r} 11110 \\ +\quad 30 \\ \hline 10101 \\ \hline 10011 \end{array} $$

负数 \# 表示符号位 1 的补码 2 的补码

13Ch13. 负数:符号幅度表示 Negative Numbers: Signed Magnitude representation P33

14Ch14. 负数:1 的补码表示 Negative Numbers: 1's Complement representation P34

15Ch15. 有符号幅度 & 1 的 补码的问题 Problems with signed mag & 1's C P35

$$ \begin{array}{r} 0101 \\ +1101 \\ \hline \end{array} $$

使用二进制加法算法

1Ch15.1. 二进制加法算法在有符号幅度下的局限性 BAA Limitations in Signed Magnitude P36

$$ \begin{array}{r} 111 \\ +0101 \\ 1101 \\ \hline 0010 \end{array} $$

2Ch15.2. 符号幅度加法错误示例 Signed Magnitude Addition Error Example P37

$$ \begin{array}{cc} 1 \quad 1 \quad 1 & \text { Signed magnitude } \\ +0101 & +5 \\ +1101 & +-5 \\ \hline 0010 & \text { Result should be } 0, \text { not } 2 \end{array} $$

使用二进制加法算法 (BAA)

3Ch15.3. 1的补码加法的问题 Problems with 1's Complement Addition P38

使用二进制加法算法 (BAA)

16Ch16. 负数:2 的补码表示 Negative Numbers: 2's complement representation P39

17Ch17. 数字编码 Number encodings P40

无符号 符号 & 幅度 1 的补码 2 的补码
000 0 +0 +0 +0
001 1 +1 +1 +1
010 2 +2 +2 +2
011 3 +3 +3 +3
100 4 0 -3 -4
101 5 -1 -2 -3
110 6 -2 -1 -2
111 7 -3 0 -1
8个值 7个值,2 个零 7个值,2 个零 8个值,1 个零

有符号幅度和 1 的补码浪费了一个位模式:2 个表示 0

无符号 符号 & 幅度 1 的补码 2 的补码
000 0 +0 +0 +0
001 1 +1 +1 +1
010 2 +2 +2 +2
011 3 +3 +3 +3
100 4 -0 -3 -4
101 5 -1 -2 -3
110 6 -2 -1 -2
111 7 -3 -0 -1
8个值 7个值,2 个零 7个值,2 个零 8个值,1 个零

1Ch17.1. 数字编码 Number encodings P41

2 的补码最小的负数表示没有正数对应 翻转位并加 1 的过程不能\\成功地取反数字
无符号 符号 & 幅度 1 的补码 2 的补码
000 0 +0 +0 +0
001 1 +1 +1 +1
010 2 +2 +2 +2
011 3 +3 +3 +3
100 4 0 -3 -4
101 5 -1 -2 -3
110 6 -2 -1 -2
111 7 -3 0 -1
8个值 7个值,2 个零 7个值,2 个零 8个值,1 个零

在 2 的补码中,二进制加法算法总是有效的(除非发生溢出)!

$$ \begin{aligned} & \text {-e.g., } \\ & \qquad \begin{array}{lr} 111 & \\ +0101 & 5 \\ +1101 & -3 \\ 0010 & 2 \end{array} \end{aligned} $$

2Ch17.2. 使用二进制加法算法 Using binary addition algorithm P42

当发生溢出时结果 $2^{\text{字长}}$

18Ch18. 2 的补码的特殊之处 What's special about 2's complement P43

1Ch18.1. 模运算与溢出的关联 Modular Arithmetic & Overflow P44

2Ch18.2. 补码环形表示(风车) Pinwheel Representation P45

011

+110

3Ch18.3. C语言中的补码示例 C Example P46

011

```

int main() {

int x = 47;

int y=-50;

unsigned int z = 50;

printf("%d %d %uln", x, y, z);

}

```

你(无意中在哪里使用过 2 的补码?

```

int main() {

int x = 47;

int y=-50;

unsigned int z = 50;

printf("%d %d %uln", x, y, z);

}

```

4Ch18.4. “翻转位+1”的直观解释 Flip bits + 1 Intuitive Proof P47

负值正好对面

2 的补码

所有位翻转的值比\\正好对面顺时针少 1 刻度

5Ch18.5. “翻转位+1”的正式证明 Flip bits + 1 Formal Proof P48

19Ch19. 表示 vs. 操作 Representation vs. Operation P49

1Ch19.1. k-位字 & 各种表示的范围 k-bit Words & Ranges P50

20Ch20. 获取表示 Getting representation P51

1Ch20.1. 获取表示 Getting representation P52

21Ch21. 表示 vs. 操作 (总结) Representation vs. Operation (Summary) P53

22Ch22. 自动化减法 Automating Subtraction P54

$$ \begin{aligned} & 001110 \\ & 010101 \end{aligned} $$

1Ch22.1. 自动化减法示例 Automating Subtraction Example P55

$$ \begin{array}{r} 001110 \\ -010101 \end{array} \longrightarrow-\begin{array}{r} 0110 \\ 010101 \\ \hline 001110 \\ \hline 000111 \end{array} $$

23Ch23. 2 的补码减法:利用 BAA 2's-complement subtraction: make use of BAA P56

$$ \begin{array}{r} 001110 \\ -010101 \\ \hline \end{array} $$

1Ch23.1. 补码减法示例 Complement Subtraction Example P57

2 的补码减法利用 BAA

$X=111001, -X=000111=7, X=-7$

24Ch24. 检测溢出 Detecting Overflow P58

对于无符号 111
1110
$\underline{1010}$
1000

25Ch25. 2 的补码中的溢出检测很简单 Overflow detection in 2's-complement is easy P59

-如果最终\\两个进位匹配则没有溢出
-
如果\\不同则溢出
- 例如,字长 $=4$
$5+1=6$ $-5+-3=-8$ $-2+7=5$ $-2+-7=-9$
00 11 11 10
+ + + +
$\underline{0001}$ $\underline{1101}$ 0111 $\underline{1001}$
0110 1000 0101 0111

$$ \begin{aligned} & \begin{array}{l} 7+7=14 \\ 0 \\ 0111 \\ +{ }_{\underline{0111}}^{\underline{0111}} \\ \text { overflow } \end{array} \end{aligned} $$

26Ch26. 为什么 2 的补码溢出检测有效的证明 Proof of why 2's complement overflow detection works P60

$O Y_{k-2} Y_{k-3} \ldots Y_{0}$

错误

加法

1Ch26.1. 情况2:两者皆负 Case 2: both negative P61

$$ \begin{aligned} & A B \\ + & 1 X_{k-2} X_{k-3} \ldots X_{0} \\ & 1 Y_{k-2} Y_{k-3} \ldots Y_{0} \end{aligned} $$

2Ch26.2. 情况3:一正一负 Case 3: one positive, other negative P62

两位字
word
关联值
Value
00 1
01 3
10 6
11 2

27Ch27. 关于溢出的最后思考 Final thoughts on Overflow P63

两位字
word
关联值
Value
00 1
01 3
10 6
11 2

$$ \begin{aligned} & 00+00=11 \text { (i.e., } 1+1=2 \text { ) } \\ & 00+01=? \text { ? } \\ & 1+3 \text { should equal } 4 \text {, but no 2-bit combo } \\ & \text { represents } 4 \end{aligned} $$

1Ch27.1. 溢出示例分析 Overflow Example Analysis P64

两位字
word
关联值
Value
00 1
01 3
10 6
11 2

$$ 00+00=11 \text { (i.e., } 1+1=2 \text { ) } $$

$$ 00+01=? ? $$

$1+3$ 应该等于 4,但没有 2-位组合表示 4

因此对于此表示,00+01 导致溢出

28Ch28. 浮点 Floating Point P65

29Ch29. 需要更大的范围?浮点表示 Need a bigger range? Floating Point Representation P66

$$ -7.776 \times 10^{3}=-7776=-6^{5} $$

尾数

注意尾数总是采用 X.XX... 形式**

(又名小数部分

(**小数点前一位)

1Ch29.1. 浮点表示示例 Floating Point Representation Example P67

$$ -7776 \times 10^{3}=-7776=-65 $$

尾数

注意尾数总是采用 X.XX... 形式**

(又名小数部分

(**小数点前一位)

$$ -1.10 \times 2^{0111}\left(=-1.5^{*} 2^{7}\right) $$

注意正确形式中,对于二进制尾数总是 1.XX... (小数点前一位,且该位\\总是 1)

唯一例外$0=0.0 \times 2^{0}$

30Ch30. 浮点数的标准形式 Standard Forms for Floating Point Numbers P68

3130292827262524232221201918171615141312111009080706050403020100

符号 小数部分 (尾数)

31Ch31. IEEE 754 浮点描述 IEEE 754 Floating Point description P69

3130292827262524232221201918171615141312111009080706050403020100

符号 指数 小数部分 (尾数)

3130292827262524232221201918171615141312111009080706050403020100

1000011011010000000000000000000

32Ch32. 偏移量和浮点数比较 Bias and Comparing floats P70

1Ch32.1. 步骤2:检查指数 Step 2: Check exponents P71

2Ch32.2. 步骤3:检查小数部分 Step 3: Check fraction P72

3Ch32.3. 步骤4:完全相等与有符号比较的相似性 Step 4: Full Equality & Signed Comparison P73

哪个 IEEE 754 FP \# 最大

33Ch33. IEEE 754 64-位 (双精度) IEEE 754 64-bit (double) precision P74

1 31/30292827262524232221201918171615141312111009080706050403020100
指数 小数部分 (高位)

3130292827262524232221201918171615141312111009080706050403020100

2 小数部分 (低位)

34Ch34. 下溢 Underflow P75

35Ch35. 讲座结束 Lecture End P76

```

```