A1.2.2 · Computer fundamentals
A1.2.2 · 计算机基础
How Binary Is Used to Store Data
二进制如何用来存储数据
A computer only stores bits. A number, a letter, a photo, a song and a film are all the same kind of thing to it: a long run of 0s and 1s. What makes one a photo and another a song is the agreed scheme for reading the bits back.
计算机只存储位。一个数字、一个字母、一张照片、一首歌和一部电影,对它来说都是同一种东西:一长串 0 和 1。让其中一个成为照片、另一个成为歌曲的,是读回这些位时所用的约定方案。
A1's guiding question asks what principles underpin how a computer works. One: a single encoding scheme, agreed in advance, is what turns raw bits into meaning, and the scheme chosen decides how much space the data takes and how quickly it can be searched.
A1 的引导性问题问的是支撑计算机运行的原理。其一:一个事先约定好的编码方案,才是把原始的位变成意义的东西,而所选的方案决定了数据占用多少空间、以及能多快被检索。
Explainer
讲解
The same bits, different meanings
同样的位,不同的含义
Binary encoding is an agreed rule that maps each pattern of bits to a meaning. The byte 01000001 is the number 65, the letter A, or one grey level, depending only on which rule is being applied. Without the rule, the bits say nothing.
二进制编码是一条约定的规则,把每一种位的组合对应到一个含义。字节 01000001 是数字 65、字母 A,还是某个灰度值,完全取决于正在应用哪条规则。没有规则,这些位什么也不表示。
Storage: the number of bits per item (per character, per pixel, per sample) fixes the file size. Retrieval: a fixed-length scheme lets the computer jump straight to item number n by multiplying, while a variable-length scheme has to be read from the start.
存储:每个单元(每个字符、每个像素、每个采样)用多少位,决定了文件大小。检索:定长方案让计算机可以用乘法直接跳到第 n 个单元,而变长方案必须从头开始读。
Explore
探索
How each data type is stored in binary
每种数据类型如何用二进制存储
The syllabus names six: integers, characters and strings, images, audio and video. Click each one to see the mechanism and the parameter that controls its size.
考纲点名了六类:整数、字符和字符串、图像、音频和视频。点击每一类,看看它的存储机制,以及决定它大小的那个参数。
Try it yourself
动手试试
A character to binary
把一个字符变成二进制
Type any single character, or pick one below. The page looks up its code-point number (ASCII where it fits, Unicode otherwise) and shows that number in binary.
输入任意一个字符,或在下方挑一个。页面会查出它的码点编号(能放进 ASCII 的就用 ASCII,否则用 Unicode),并把这个编号显示为二进制。
Letters a to z and A to Z sit in a block: each capital is exactly 32 less than its lowercase partner, which is why flipping one bit (the 32s bit) changes case. Characters beyond the basic Latin set need a larger Unicode number and more than one byte.
字母 a 到 z 和 A 到 Z 排成一段:每个大写字母正好比它对应的小写字母小 32,所以翻转一个位(32 那一位)就能改变大小写。基本拉丁字母以外的字符需要更大的 Unicode 编号和不止一个字节。
Explainer
讲解
Effect on storage and retrieval
对存储和检索的影响
| Choice in the scheme | Effect on storage | Effect on retrieval |
|---|---|---|
| More bits per item (higher colour depth, higher bit depth, wider integers) | Larger files, slower to copy or send | Each item takes longer to read and process |
| Fixed length per item (8-bit ASCII, 32-bit integers) | Predictable size, sometimes wasteful for small values | Item n is found instantly by multiplying n by the item size |
| Variable length per item (UTF-8 text, compressed media) | Smaller for common cases, no wasted space | Must be scanned from the start; cannot jump to item n directly |
| Encoding designed for indexing (sorted keys, hashed values) | Small overhead for the index structure | Large data sets can be searched quickly rather than element by element |
| 方案中的选择 | 对存储的影响 | 对检索的影响 |
|---|---|---|
| 每个单元用更多位(更高的色深、更高的位深、更宽的整数) | 文件更大,复制或传输更慢 | 每个单元读取和处理都更慢 |
| 每个单元定长(8 位 ASCII、32 位整数) | 大小可预测,对小的值有时会浪费 | 把 n 乘以单元大小,就能立即定位第 n 个单元 |
| 每个单元变长(UTF-8 文本、压缩后的媒体) | 常见情况下更小,不浪费空间 | 必须从头扫描;不能直接跳到第 n 个单元 |
| 为便于索引而设计的编码(有序的键、哈希后的值) | 索引结构有少量额外开销 | 大数据集可以快速搜索,而不必逐个元素查找 |
Error detection is often built into the scheme too: a parity bit added to each byte lets a later read catch a single flipped bit, which matters for reliable retrieval from storage or over a network.
方案里通常还内建了错误检测:给每个字节加一个奇偶校验位,之后读取时就能发现一个被翻转的位,这对从存储介质或通过网络可靠地取回数据很重要。
Check your understanding
检验你的理解
A bitmap image is changed from 8-bit colour depth to 16-bit, with the same dimensions. What happens?
一张位图的色深从 8 位改为 16 位,尺寸不变。会发生什么?
Common mistake
常见错误
RecurringAnswers name a file format ("it is saved as a JPEG", "it is an MP3") and stop there. The command term is explain, so the marks are for the mechanism: an image is a grid of pixels, each pixel a set of bits giving its colour; audio is the wave measured many times a second, each measurement a binary number; video is a sequence of those images shown fast. A second slip: writing "colour depth" when the answer needs "number of colours", or the reverse. Colour depth is the bit count; the number of colours is 2 raised to that count.
反复出现答案说出一个文件格式("它存成 JPEG""它是 MP3")就停下了。命令词是 explain,所以分数是给机制的:图像是一个像素网格,每个像素是一组给出其颜色的位;音频是把声波每秒测量许多次,每次测量是一个二进制数;视频是把这些图像快速连续播放的序列。第二个错误:该说"颜色数"时写成"色深",或反过来。色深是位数;颜色数是 2 的该位数次方。
Wrong: "A photo is stored in binary by saving it as a JPEG file, and sound is stored as an MP3."
错误: "照片通过存成 JPEG 文件的方式用二进制存储,声音存成 MP3。"
Right: "A photo is a grid of pixels. Each pixel stores a binary number for its colour, for example three 8-bit values for red, green and blue. Sound is sampled: its level is measured thousands of times a second and each measurement is stored as a binary number whose range is set by the bit depth."
正确: "照片是一个像素网格。每个像素为它的颜色存储一个二进制数,例如红、绿、蓝三个 8 位的值。声音被采样:它的电平每秒被测量数千次,每次测量存成一个二进制数,其取值范围由位深决定。"
Revision questions
复习题
Specimen-paper style. Write an answer, then reveal the marking points and mark yourself.
采用样卷风格。写下答案,然后展开评分要点给自己打分。
[2]Explain why the same 8 bits can represent both a number and a character.
[2]解释为什么同样的 8 个位既能表示一个数,又能表示一个字符。
Marking points
评分要点
- Binary encoding is an agreed rule that maps each bit pattern to a meaning.
- The same eight bits mean a number under one rule and a character under another; the bits alone say nothing until a rule is applied.
- 二进制编码是一条约定的规则,把每种位的组合映射到一个含义。
- 同样的八个位,在一条规则下表示数字,在另一条规则下表示字符;在应用规则之前,这些位本身什么也不表示。
[3]Describe how a bitmap image is represented in binary.
[3]描述位图如何用二进制表示。
Marking points
评分要点
- A bitmap image is stored as a grid of pixels.
- Each pixel is a set of bits giving its colour, for example three 8-bit values for red, green and blue.
- The image size in bits is the number of pixels multiplied by the number of bits per pixel (the colour depth).
- 位图图像被存储为一个像素网格。
- 每个像素是一组给出其颜色的位,例如红、绿、蓝各一个 8 位的值。
- 图像的位数是像素数乘以每像素的位数(色深)。
[4]Explain how sound is converted to and stored in binary, referring to sampling rate and bit depth.
[4]解释声音如何转换成二进制并存储,提到采样率和位深。
Marking points
评分要点
- The sound wave is sampled: its level is measured at fixed moments, many thousands of times per second.
- The number of samples per second is the sampling rate.
- Each measurement is stored as a binary number; the number of bits per sample is the bit depth, which sets how finely the level is recorded.
- The file size in bits is sampling rate x bit depth x length in seconds (x number of channels).
- 声波被采样:它的电平在固定时刻被测量,每秒许多千次。
- 每秒的样本数是采样率。
- 每次测量被存储为一个二进制数;每个样本的位数是位深,它决定电平被记录的精细程度。
- 文件的位数是采样率 x 位深 x 时长(秒)(x 声道数)。
[4]Explain how the choice of a fixed-length versus a variable-length encoding affects both the size of a file and the speed of finding an item within it.
[4]解释选择定长编码还是变长编码,如何影响文件的大小以及在其中查找某个单元的速度。
Marking points
评分要点
- Size: a fixed-length encoding uses the same number of bits for every item, which can waste space on small values but is predictable; a variable-length encoding uses fewer bits for common items, so the file is usually smaller.
- Finding an item: with a fixed length, item n is found instantly by multiplying n by the item size; with a variable length, the data must be scanned from the start because you cannot know where item n begins.
- 大小:定长编码对每个单元用相同的位数,对小的值可能浪费空间,但大小可预测;变长编码对常见单元用更少的位,所以文件通常更小。
- 查找单元:定长时,把 n 乘以单元大小就能立即定位第 n 个单元;变长时,必须从头扫描数据,因为你无法知道第 n 个单元从哪里开始。
[3]Explain why storing video as a plain sequence of full images is impractical, and name the two kinds of redundancy that compression removes.
[3]解释为什么把视频存成一串完整图像不切实际,并说出压缩去除的两种冗余。
Marking points
评分要点
- A single second of video is many full images, so storing every frame in full would produce a very large file.
- Compression removes two kinds of redundancy: spatial redundancy (large areas within one frame that are the same or similar) and temporal redundancy (parts of the picture that barely change from one frame to the next).
- 一秒钟的视频是许多张完整的图像,所以把每一帧都完整存下来会产生非常大的文件。
- 压缩去掉两种冗余:空间冗余(一帧内部大片相同或相似的区域)和时间冗余(画面中从一帧到下一帧几乎不变的部分)。
Flashcards
记忆卡片
Active recall for this statement’s key terms.
针对本条考纲陈述关键术语的主动回忆练习。
Keep this statement’s practice with you
把这条考纲陈述的练习保存下来
Free account: unlock every revision question and flashcard for A1.2.2, and every other IB CS 2027 statement.
免费账户:解锁 A1.2.2 以及所有其他 IB CS 2027 考纲陈述的全部复习题和记忆卡片。