Lec 1-1:数字的表示和处理¶
Representing and Manipulating Information

- primitive type 基本类型:编程语言中最基本的数据类型
Binary number representation¶
二进制数的表示与计算
Analog 模拟信号 Continuous in value and time
Digital 数字信号
- Asynchronous 非同步信号 Discrete in value & continuous in time
-
Synchronous 同步信号 Discrete in value and time(有严格周期)
数字取值+采样时间均离散
噪音
Threshold 阈值
Threshold Region
Different Radixes
| Name | Radix | Digits |
|---|---|---|
| Binary | 2 | 0,1 |
| Octal | 8 | 0~7 |
| Decimal | 10 | 0~9 |
| Hexadecimal | 16 | 0~9 + A~F |
Converting R-base to Decimal¶
R进制 转 十进制 十进制 转 R进制
整数部分 整除取余 下 → 上 小数部分 乘R取整 直至整数 上 → 下
十六&二&八:十六每一位对应二的四位,八的三位
\(1\ K = 2^{10}\) (1024) \(1\ M = 2^{20}\) (1,048,576) \(1\ G = 2^{30}\) \(1\ T = 2^{40}\)
Arithmetic Oprerations¶
- Single Bit Binary Addition with Carry
- Multiple Bit Binary Addtion
- Single Bit Binary Subtraction with Borrow
0 - 1 ———— 1 1
- Multiple Bit Binary Subtraction
- Binary Multiplication
乘法器 -- 加法器 + 位移 -> 数据移动
- Binary Division
除法 需要比大小试错 -- 除法器
Lec 1-2¶
Representation of numeric data¶
-
Elements to Represent Numerical Data
-
Carry counting system
- Number representation
- Fixed-point vs. floating-point
-
Encoding method
-
Representation of Numeric Data
- Fixed-point number representation
machine number -- true value
Encoding Methods¶
-
Original code
-
Complement code
取模运算 \(X_T > 0, [X_T]_C = X_T = M + X_T(mod\ M)\) \(X_T < 0, [X_T]_C = M - |X_T| = M + X_T(mod\ M)\)
补码计算 -- 保证连续
原 → 补:取反 +1 补 → 原:-1 取反,注意符号
example
e.g.
1 0 1
\(-1\) x \(2^2\) + \(0\) x \(2^1\) + \(1\) x \(2^0\)
第一位--符号位 先正常看待(都当无符号),计算时,第一位加上本来的符号,再与后面相加
\(T_{Min} = -2^{n-1}\)
\(T_{Max} = 2^{n-1}-1\)
边界问题,最大/小值,0处
不同位补码表示 + 补0 - 补1
有进位时,溢出两种情况
加法器:标志位 -- 符号位、溢出位 判断
-
Inverse code
-
Frameshift code
| s | exp | frac |
unsigned integers signed integers
C 中 unsigned int 会自动转化为 signed int 进行计算 → 可能溢出
位运算 / 逻辑运算
& | ! ~ >> <<
补充:Code Security Example C语言中边界跨越 默认操作 溢出风险判断
3.09 1h03min
扩展
四 -> 八 -> 十六
最高位补 0 / 1
最高位变化 符号位,溢出位
最高位翻转
取模
6 + 7 = 13
0 1 1 1 0 1 1 0 ———————— 1 1 0 1
\(-2^{n-1}\) + \(2^{n-2}\) + …… (符号位)
图形化演示/取模的可视化
! 最高位 \(-2^{n-1}\)
乘法: 有符号,无符号
结果长度?
计算时
16位 x 16位 -> 两个 16 位
所以十六位的系统一般 限制 8 x 8
浮点数 精度损失 -> 推理下降
ai 神经网络 参数 矩阵
- 忽略最高位
- 有符号 截断?
移位 算术左移/右移
高位补齐,低位添0
Floating number¶
浮点数表达
末位截断
| s | exp | frac |
\((-1)^s M 2^E\)