Data storage and compression
引入
15:06
计算机为何使用二进制
处理器内部有数十亿个微型开关。每个开关只能处于开或关的状态。这就是计算机物理上拥有的全部——没有三,没有七,没有…
英文讲解 · 可切换中英文字幕
本课内容
| English | 释义 | 拼音 |
|---|---|---|
| Data storage | 数据存储 | shù jù cún chǔ |
| sound file | 音频文件 | yīn pín wén jiàn |
| Compression/kəmˈpreʃn/ | 压缩 | yā suō |
| bit/bɪt/ | 位 | wèi |
| nibble/ˈnɪbl/ | 半字节 | bàn zì jié |
| byte/baɪt/ | 字节 | zì jié |
| kibibyte/ˈkɪbɪbaɪt/ | 二进制千字节 | èr jìn zhì qiān zì jié |
| binary/ˈbaɪnəri/ | 二进制 | èr jìn zhì |
| colour depth/ˈkʌlə depθ/ | 颜色深度 | yán sè shēn dù |
| sample rate/ˈsæmpl reɪt/ | 采样率 | cǎi yàng lǜ |
| sample resolution/ˈsæmpl ˌrezəˈluːʃn/ | 采样分辨率 | cǎi yàng fēn biàn lǜ |
| bpp | 每像素位数 | měi xiàng sù wèi shù |
| Lossless/ˈlɒsləs/ | 无损 | wú sǔn |
| run-length encoding/rʌn leŋθ enˈkəʊdɪŋ/ | 行程编码 | xíng chéng biān mǎ |
| run/rʌn/ | 游程 | yóu chéng |
| Lossy/ˈlɒsi/ | 有损 | yǒu sǔn |
| resolution/ˌrezəˈluːʃn/ | 分辨率 | fēn biàn lǜ |
| program files | 程序文件 | chéng xù wén jiàn |
| Hz | 赫兹 | hè zī |
| characters/ˈkærɪktəz/ | 字符 | zì fú |
把文件压缩得更小
- 数据存储以不同单位衡量,每一级单位是前一级的 1024 倍。
- 我们可以计算图像或声音文件的大小。
- 压缩可以使文件更小。
衡量存储容量
- 位(一个 0 或 1)· 半字节(4 位)· 字节(8 位)。
- 之后每个单位都是前一个单位的 1024 倍(因为 $1024 = 2^{10}$):二进制千字节(KiB) = 1024 字节,二进制兆字节(MiB) = 1024 KiB,二进制吉字节(GiB) = 1024 MiB,二进制太字节(TiB) = 1024 GiB。
- 换算成上一级单位时,始终除以 1024(而不是 1000)。

How many bytes are in 1 kibibyte (KiB)?
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
1 KiB = 1024 bytes (each storage unit steps up by 1024 = 2^10).
Match each storage/compression idea to its meaning.
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
File size grows with detail; compression shrinks it, losslessly or lossily.
计算文件大小
- 图像(位)$=$ 宽度 × 高度 × 色彩深度。
- 声音(位)$=$ 采样率 × 采样分辨率 × 秒数。
- 除以 8 得到字节,再除以 1024 得到 KiB,再除以 1024 得到 MiB。
- 例如,$1024 \times 1024$ 的色彩深度为每像素 16 位 $= 16\,777\,216$ 位 $= 2$ MiB。
An image is 100 × 100 pixels with a colour depth of 24 bits. What is its size in bits?
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
width × height × colour depth = 100 × 100 × 24 = 240 000 bits.
压缩
- 无损压缩使文件更小,且没有永久损失——可以精确恢复原文件。**行程编码(RLE)**将一段重复的游程存储一次(例如
WWWWWWWW→ “8 W”)。 - 有损压缩通过永久移除数据(降低分辨率或采样率)使文件小得多。
- 文本和程序文件使用无损压缩;照片、音乐和视频使用有损压缩。

Run-length encoding shrinks repeats
Compression makes a file smaller. Run-length encoding replaces a run of identical values with one value plus a count — lossless, and best when the data has long runs.
Lossless compression:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Lossless keeps all the data (e.g. RLE); lossy permanently discards some.
Run-length encoding (RLE) compresses data by:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
RLE replaces a run like WWWWWWWW with "8 W" — great when data has many repeats.
Lossy compression is most appropriate for:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Lossy suits media where a slight quality loss buys a much smaller file; exact data needs lossless.
例题:声音文件与 RLE
一段 10 秒的声音以 8000 Hz(赫兹)的采样率录制,采样分辨率为 16 位。求它的大小,单位为 KiB。然后用行程编码压缩这串字符:WWWWWWBBBW。
- 先相乘,再逐级换算单位:
- RLE 将每段游程存储为一组数量和值:6W 3B 1W。10 个字符变成三组,且没有任何损失,所以这是无损压缩。

An image is 100 pixels wide and 50 pixels high, with a colour depth of 8 bits. What is its size in bytes?
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
$100 \times 50 \times 8 = 40\,000$ bits, and $40\,000 \div 8 = 5000$ bytes.
Which file must be compressed with a lossless method?
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
If even one bit of a program changes, it will not run correctly; photos, music and video can lose detail people do not notice.
你掌握了
- 存储单位以 1024 增大(KiB、MiB、GiB、TiB)
- 图像大小 = 宽度 × 高度 × 色彩深度(位);声音 = 采样率 × 采样分辨率 × 秒数
- 无损 = 精确恢复(RLE);有损 = 更小,永久损失
- 文本/程序用无损;照片/音乐/视频用有损
出了什么问题?只有网站团队能看到这些信息。