一台计算机只能用两个状态工作:开和关。你把这些写成 1 和 0。一个只用两个数字(digits)的系统叫二进制(binary,基数 2)。

每种数据(data)——数字、文本、声音和图像——在计算机能使用它之前都必须被变成二进制。计算机用逻辑门(logic gates)处理这个二进制,并把它存储在寄存器(registers,处理器(processor)内部的小的、快速的存储)中。

IGCSE 计算机科学 · 第 1 主题
一台计算机只能用两个状态工作:开和关。你把这些写成 1 和 0。一个只用两个数字(digits)的系统叫二进制(binary,基数 2)。

每种数据(data)——数字、文本、声音和图像——在计算机能使用它之前都必须被变成二进制。计算机用逻辑门(logic gates)处理这个二进制,并把它存储在寄存器(registers,处理器(processor)内部的小的、快速的存储)中。

| 英文 | 中文 | 拼音 |
|---|---|---|
| digit | 数字 | shù zì |
| binary | 二进制 | èr jìn zhì |
| data | 数据 | shù jù |
| logic gate | 逻辑门 | luó jí mén |
| processor | 处理器 | chǔ lǐ qì |
| register | 寄存器 | jì cún qì |
| Candidates should be able to: | Notes and guidance |
|---|---|
| 1 Understand how and why computers use binary to represent all forms of data | • Any form of data needs to be converted to binary to be processed by a computer • Data is processed using logic gates and stored in registers |
| 2 (a) Understand the denary, binary and hexadecimal number systems (b) Convert between (i) positive denary and positive binary (ii) positive denary and positive hexadecimal (iii) positive hexadecimal and positive binary | • Denary is a base 10 system • Binary is a base 2 system • Hexadecimal is a base 16 system • Values used will be integers only • Conversions in both directions, e.g. denary to binary or binary to denary • Maximum binary number length of 16-bit |
| 3 Understand how and why hexadecimal is used as a beneficial method of data representation | • Areas within computer science that hexadecimal is used should be identified • Hexadecimal is easier for humans to understand than binary, as it is a shorter representation of binary |
| 4 (a) Add two positive 8-bit binary integers (b) Understand the concept of overflow and why it occurs in binary addition | • An overflow error will occur if the value is greater than 255 in an 8-bit register • A computer or a device has a predefined limit that it can represent or store, for example 16-bit • An overflow error occurs when a value outside this limit should be returned |
| 5 Perform a logical binary shift on a positive 8-bit binary integer and understand the effect this has on the positive binary integer | • Perform logical left shifts • Perform logical right shifts • Perform multiple shifts • Bits shifted from the end of the register are lost and zeros are shifted in at the opposite end of the register • The positive binary integer is multiplied or divided according to the shift performed • The most significant bit(s) or least significant bit(s) are lost |
| 6 Use the two’s complement number system to represent positive and negative 8-bit binary integers | • Convert a positive binary or denary integer to a two’s complement 8-bit integer and vice versa • Convert a negative binary or denary integer to a two’s complement 8-bit integer and vice versa |
来源:剑桥国际大纲
一个数制(number system)是用一组固定的数字书写数字的方式。你需要其中三个。
| 系统 | 基数 | 使用的数字 |
|---|---|---|
| 十进制 | 10 | 0–9 |
| 二进制 | 2 | 0 和 1 |
| 十六进制 | 16 | 0–9 然后 A–F |
基数(base)告诉你一个系统用多少个不同的数字。
一个数中的每一列有一个位值(place value)。在二进制中位值从右到左翻倍。对一个 8 位数它们是:
128 64 32 16 8 4 2 1

一个位(bit)是一个单一的 0 或 1。八个位构成一个字节(byte)。四个位(半个字节)是一个半字节(nibble)。
十进制 → 二进制。 写出位值。在你需要的每个值下面放一个 1,使它们加起来为你的数;在其余的下面放 0。
例子:把十进制 150 变成二进制。$150 = 128 + 16 + 4 + 2$。
128 64 32 16 8 4 2 1
1 0 0 1 0 1 1 0
所以 $150$ = 10010110。
二进制 → 十进制。 加上有 1 的位值。10010110 $= 128 + 16 + 4 + 2 = 150$。
十六进制 → 二进制。 把每个十六进制数字变成它自己的 4 位组(一个半字节)。
例子:十六进制 F08。$F = 1111$,$0 = 0000$,$8 = 1000$,所以 F08 = 1111 0000 1000。

二进制 → 十六进制。 把位分成 4 个的半字节,从右边开始。把每个半字节变成一个十六进制数字。
十进制 → 十六进制。 简单的方式是先变成二进制,然后二进制变成十六进制。
这个表格帮助记十六进制字母:
| 十进制 | 二进制 | 十六进制 |
|---|---|---|
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
Cambridge 的题目用长达 16 位的二进制数。
例题。 把十进制 100 转换成 8 位二进制,然后转换成十六进制。
$100 = 64 + 32 + 4$,所以二进制是 01100100。分成半字节,0110 0100 $= 6$ 和 $4$,所以十六进制是 64。
十六进制比二进制更短,对人们更容易读和写。一个十六进制数字替换 4 个二进制数字,所以你犯更少的错误。值不改变——十六进制只是显示同样的二进制的一个更短的方式。
计算机科学家把十六进制用于:
#FF0000 是红色)Type a number and see it in binary, denary and hex — and how the place values build it.
| 英文 | 中文 | 拼音 |
|---|---|---|
| number system | 数制 | shù zhì |
| denary | 十进制 | shí jìn zhì |
| hexadecimal | 十六进制 | shí liù jìn zhì |
| base | 基数 | jī shù |
| place value | 位值 | wèi zhí |
| bit | 位 | wèi |
| byte | 字节 | zì jié |
| nibble | 半字节 | bàn zì jié |
| memory address | 内存地址 | nèi cún dì zhǐ |
你可以把两个 8 位二进制数相加,从右边逐列,就像十进制。一列的规则是:
| A | B | 结果位 | 进位 |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
当一个进位也进来时,$1 + 1 + 1 = 1$ 带一个 1 的进位。
例子:把 01110110(118)和 00110000(48)相加。
0 1 1 1 0 1 1 0 (118)
+ 0 0 1 1 0 0 0 0 (48)
-------------------
1 0 1 0 0 1 1 0 (166)

一个 8 位寄存器只能容纳 0 到 255 的十进制值。若一个加法给出一个 255 以上的结果,答案需要一个第 9 位。寄存器不能容纳这个额外的位,所以它丢失了。这叫溢出(overflow,一个溢出错误)。它在一个值超出寄存器能存储的极限时发生。
例子:11001000(200)$+$ 01001000(72)$= 272$。用二进制那是 1 00010000,它需要 9 位。前导的 1 在 8 位中放不下,所以存储的答案错误。

| 英文 | 中文 | 拼音 |
|---|---|---|
| overflow | 溢出 | yì chū |
一个逻辑二进制移位(logical binary shift)把所有的位左移或右移若干位。
一个左移每移一位把数乘以 2。一个右移每移一位把它除以 2;最右边的位(最低有效位(least significant bit(s)))丢失。
例子:把 00110101(53)左移 2 位。
start: 0 0 1 1 0 1 0 1
left shift 2: 1 1 0 1 0 1 0 0

结果是 11010100(212),它是 $53 \times 4$。最左边的两位丢失,而两个零从右边进来。若一个 1 被推出末端,那个信息就永远消失了。
| 英文 | 中文 | 拼音 |
|---|---|---|
| logical binary shift | 逻辑二进制移位 | luó jí èr jìn zhì yí wèi |
| least significant bit | 最低有效位 | zuì dī yǒu xiào wèi |
到目前为止这些数是正的。补码(two's complement)让一个 8 位寄存器也容纳负数。
在补码中,最左边的位(最高有效位(most significant bit),或 MSB)有一个负的位值:
-128 64 32 16 8 4 2 1
要使一个正数变负: 写出正的二进制,翻转每个位(0↔1),然后加 1。
例子:制造 $-40$。
001010001101011111011000所以 $-40$ = 11011000。通过加上位值检查:$-128 + 64 + 16 + 8 = -40$。

要读一个负的补码数,只需加上位值(MSB 算作 $-128$)。一个 8 位补码数的范围是 $-128$ 到 $+127$。
| 英文 | 中文 | 拼音 |
|---|---|---|
| two's complement | 补码 | bǔ mǎ |
| most significant bit | 最高有效位 | zuì gāo yǒu xiào wèi |
| Candidates should be able to: | Notes and guidance |
|---|---|
| 1 Understand how and why a computer represents text and the use of character sets, including American standard code for information interchange (ASCII) and Unicode | • Text is converted to binary to be processed by a computer • Unicode allows for a greater range of characters and symbols than ASCII, including different languages and emojis • Unicode requires more bits per character than ASCII |
| 2 Understand how and why a computer represents sound, including the effects of the sample rate and sample resolution | • A sound wave is sampled for sound to be converted to binary, which is processed by a computer • The sample rate is the number of samples taken in a second • The sample resolution is the number of bits per sample • The accuracy of the recording and the file size increases as the sample rate and resolution increase |
| 3 Understand how and why a computer represents an image, including the effects of the resolution and colour depth | • An image is a series of pixels that are converted to binary, which is processed by a computer • The resolution is the number of pixels in the image • The colour depth is the number of bits used to represent each colour • The file size and quality of the image increase as the resolution and colour depth increase |
来源:剑桥国际大纲
计算机通过给每个字符一个数字、然后把那个数字存储为二进制来存储文本。一台计算机能使用的字符集,连同它们的数字,是一个字符集(character set)。
因为 Unicode 有更多的字符,它每个字符需要比 ASCII 更多的位,所以同样的文本占用更多的存储(storage)。

| 英文 | 中文 | 拼音 |
|---|---|---|
| character set | 字符集 | zì fú jí |
| emoji | 表情符号 | biǎo qíng fú hào |
| storage | 存储 | cún chǔ |
一个声波(sound wave)平滑而一直在变。要存储它,计算机在规律的时刻测量波的高度。这叫采样(sampling),而每次测量是一个样本。

一个更高的采样率和一个更高的采样分辨率给一个更准确的录音,但一个更大的文件。
y = a sin(bt + c)
Sound is a wave; sampling records its height many times a second.
| 英文 | 中文 | 拼音 |
|---|---|---|
| sound wave | 声波 | shēng bō |
| sampling | 采样 | cǎi yàng |
| sample rate | 采样率 | cǎi yàng lǜ |
| sample resolution | 采样分辨率 | cǎi yàng fēn biàn lǜ |
| amplitude | 振幅 | zhèn fú |
| resolution | 分辨率 | fēn biàn lǜ |
一个计算机图像由叫像素(pixels)的小点的一个网格构成。

一个更高的分辨率和一个更高的颜色深度给一个更好质量的图像,但一个更大的文件。
| 英文 | 中文 | 拼音 |
|---|---|---|
| pixel | 像素 | xiàng sù |
| colour depth | 颜色深度 | yán sè shēn dù |
| Candidates should be able to: | Notes and guidance |
|---|---|
| 1 Understand how data storage is measured | • Including: – bit – nibble – byte – kibibyte (KiB) – mebibyte (MiB) – gibibyte (GiB) – tebibyte (TiB) – pebibyte (PiB) – exbibyte (EiB) • The amount of the previous denomination present in the data storage size, e.g.: – 8 bits in a byte – 1024 mebibytes in a gibibyte |
| 2 Calculate the file size of an image file and a sound file, using information given | • Answers must be given in the units specified in the question. Calculations must use the measurement of 1024 and not 1000 • Information given may include: – image resolution and colour depth – sound sample rate, resolution and length of track |
| 3 Understand the purpose of and need for data compression | • Compression exists to reduce the size of the file • What the impact of this is, e.g.: – less bandwidth required – less storage space required – shorter transmission time |
| 4 Understand how files are compressed using lossy and lossless compression methods | • Lossy compression reduces the file size by permanently removing data, e.g. reducing resolution or colour depth, reducing sample rate or resolution • Lossless compression reduces the file size without permanent loss of data, e.g. run length encoding (RLE) |
来源:剑桥国际大纲
数据存储用下面的单位测量。一个半字节是 4 位,一个字节是 8 位;从千字节(KiB)往上,每个单位是它之前的那个的 1024 倍(因为 $1024 = 2^{10}$,它适合二进制)。
| 单位 | 等于 |
|---|---|
| bit | 一个单一的 0 或 1 |
| nibble | 4 位 |
| byte | 8 位 |
| kibibyte (KiB) | 1024 字节 |
| mebibyte (MiB) | 1024 KiB |
| gibibyte (GiB) | 1024 MiB |
| tebibyte (TiB) | 1024 GiB |
| pebibyte (PiB) | 1024 TiB |
| exbibyte (EiB) | 1024 PiB |

图像文件大小(以位计)$=$ 分辨率 $\times$ 颜色深度 $=$ 宽 $\times$ 高 $\times$ 颜色深度。
例子:一个图像是 $1024 \times 1024$ 像素,颜色深度为 2 字节($= 16$ 位)。
声音文件大小(以位计)$=$ 采样率 $\times$ 采样分辨率 $\times$ 以秒计的长度。
总是除以 1024(不是 1000)以变成 KiB、MiB 等等。以题目要求的单位给出你的答案。
例题。 一个声音以 8,000 Hz 的采样率、16 位的采样分辨率被录制 30 秒。求以千字节(KiB)计的文件大小。
压缩(compression)使一个文件更小。一个更小的文件:
有两种类型。
无损(lossless)压缩使文件更小而没有永久损失数据。原始文件能被精确地重建。
一种方法是行程编码(run-length encoding,RLE)。它用值的一个副本和它重复多少次的一个计数替换一个重复值的行程。例如 WWWWWWWW(8 个白)被存储为"8 W"。这在数据有许多重复时工作得好。

有损(lossy)压缩通过永久移除一些数据使文件小得多。移除的数据不能取回。例如:
当你必须保留每个细节时(文本和程序文件)用无损。对照片、音乐和视频用有损,那里一个小的质量损失换来一个小得多的文件是值得的。
Watch repeated symbols get squashed into a count — simple lossless compression.
| 英文 | 中文 | 拼音 |
|---|---|---|
| compression | 压缩 | yā suō |
| bandwidth | 带宽 | dài kuān |
| transmission | 传输 | chuán shū |
| lossless | 无损 | wú sǔn |
| run-length encoding | 行程编码 | xíng chéng biān mǎ |
| lossy | 有损 | yǒu sǔn |
逐步学习,并即时检测练习。