跳到主要内容

数据表示

IGCSE 计算机科学 · 知识点 1

本主题的视频课程 打开视频页面
21:16

计算机为何使用二进制

处理器内部有数十亿个微型开关。每个开关只能处于开或关的状态。这就是计算机物理上拥有的全部——没有三,没有七,没有…

英语旁白 · 英中内嵌字幕

1.1

计算机为何使用二进制

English

Digital computers represent data using two logical states, written as 1 and 0. A system that uses only two digits 数字 is called binary 二进制 (base 2).

A field of blue binary digits, 0s and 1s
Computers represent all data — numbers, text, sound and images — as binary strings of 0s and 1s

Every kind of data 数据 — numbers, text, sound and images — must be changed into binary before a computer can use it. The computer processes this binary using logic gates 逻辑门, and stores it in registers 寄存器 (small, fast stores inside the processor 处理器).

The silicon die of a microprocessor under magnification
A microprocessor holds millions of tiny transistors, each a switch that is on (1) or off (0) — the physical basis of binary
词汇 训练
English 中文 拼音
digit/ˈdɪdʒɪt/ 数字 shù zì
binary/ˈbaɪnəri/ 二进制 èr jìn zhì
data/ˈdeɪtə/ 数据 shù jù
logic gate/ˈlɒdʒɪk ɡeɪt/ 逻辑门 luó jí mén
processor/ˈprəʊsesə/ 处理器 chǔ lǐ qì
register/ˈredʒɪstə/ 寄存器 jì cún qì
1.1

数制

教学大纲
考生应能: 注释与指导
1 理解并解释计算机为何使用二进制来表示所有形式的数据 • 任何形式的数据都需要转换为二进制才能被计算机处理 • 数据通过逻辑门进行处理,并存储在寄存器中
2 (a) 理解十进制、二进制和十六进制数制 (b) 在以下之间进行转换:(i) 正十进制与正二进制;(ii) 正十进制与正十六进制;(iii) 正十六进制与正二进制 • 十进制是基数为10的数制 • 二进制是基数为2的数制 • 十六进制是基数为16的数制 • 所用数值仅为整数 • 双向转换,例如从十进制到二进制或从二进制到十进制 • 最大二进制数为16位
3 理解并解释为何使用十六进制作为有益的数据表示方法 • 应指出计算机科学中使用十六进制的领域 • 十六进制比二进制更容易被人理解,因为它是二进制的更短表示形式
4 (a) 对两个正8位二进制整数进行加法运算 (b) 理解溢出的概念及其在二进制加法中发生的原因 • 如果在8位寄存器中的值大于255,则会发生溢出错误 • 计算机或设备具有其可以表示或存储的预设上限,例如16位 • 当需要返回超出此上限的值时,会发生溢出错误
5 对正8位二进制整数执行逻辑移位,并理解该操作对正二进制整数的影响 • 执行逻辑左移 • 执行逻辑右移 • 执行多次移位 • 从寄存器末端移出的位将丢失,并在寄存器的另一端移入零 • 正二进制整数会根据执行的移位操作进行乘法或除法运算 • 最高有效位或最低有效位会丢失
6 使用补码数制来表示正负8位二进制整数 • 将正二进制或十进制整数转换为8位补码整数,反之亦然 • 将负二进制或十进制整数转换为8位补码整数,反之亦然

来源:Cambridge International 教学大纲

English
Counting in binary: 0 to 15

A number system 数制 is a way of writing numbers using a fixed set of digits. You need three of them.

System Base Digits used
Denary 10 0–9
Binary 2 0 and 1
Hexadecimal 16 0–9 then A–F
  • denary 十进制 is the normal counting system (also called decimal).
  • binary uses only 0 and 1.
  • hexadecimal 十六进制 (hex) uses sixteen digits: 0–9, then A, B, C, D, E, F stand for 10, 11, 12, 13, 14, 15.

The base 基数 tells you how many different digits a system uses.

Place value

Each column in a number has a place value 位值. In binary the place values double from right to left. For an 8-bit number they are:

128  64  32  16  8  4  2  1
An 8-bit place-value chart with values 128 down to 1, and the bits of 150 placed under the columns that sum to 150
An 8-bit place-value chart: the 1s sit under the values that add up to 150

One bit 位 is a single 0 or 1. Eight bits make one byte 字节. Four bits (half a byte) is a nibble 半字节.

Converting between number systems

Denary → binary. Write the place values. Put a 1 under each value you need so they add up to your number; put 0 under the rest.

Example: change denary 150 to binary. $150 = 128 + 16 + 4 + 2$.

128 64 32 16 8 4 2 1
  1  0  0  1 0 1 1 0

So $150$ = 10010110.

Binary → denary. Add the place values where there is a 1. 10010110 $= 128 + 16 + 4 + 2 = 150$.

Hexadecimal → binary. Change each hex digit into its own 4-bit group (a nibble).

Example: hex F08. $F = 1111$, $0 = 0000$, $8 = 1000$, so F08 = 1111 0000 1000.

Three hexadecimal digits F, 0 and 8, each with an arrow down to its own group of four bits
Each hex digit maps to its own 4-bit nibble — F08 = 1111 0000 1000

Binary → hexadecimal. Group the bits into nibbles of 4, starting from the right. Change each nibble to one hex digit.

Denary → hexadecimal. The easy way is to change to binary first, then binary to hex.

This table helps with the hex letters:

Denary Binary Hex
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F

Cambridge questions use binary numbers up to 16 bits long.

Worked example. Convert denary 100 to 8-bit binary, then to hexadecimal.

$100 = 64 + 32 + 4$, so the binary is 01100100. Splitting into nibbles, 0110 0100 $= 6$ and $4$, so the hexadecimal is 64.

Why hexadecimal is used

Hex is shorter than binary and easier for people to read and write. One hex digit replaces 4 binary digits, so you make fewer mistakes. The value does not change — hex is just a shorter way to show the same binary.

Computer scientists use hex for:

  • MAC addresses and IPv6 addresses
  • colour codes in HTML (for example #FF0000 is red)
  • memory addresses 内存地址 and error codes
  • showing the contents of memory (a "memory dump")
探索

二进制、十进制和十六进制

输入一个数字,查看其二进制、十进制和十六进制表示——以及位值如何构建它。

词汇 训练
English 中文 拼音
number system/ˈnʌmbə ˈsɪstəm/ 数制 shù zhì
denary/ˈdiːnəri/ 十进制 shí jìn zhì
hexadecimal/ˌheksəˈdesɪml/ 十六进制 shí liù jìn zhì
base/beɪs/ 基数 jī shù
place value/pleɪs ˈvæljuː/ 位值 wèi zhí
bit/bɪt/ 位 wèi
byte/baɪt/ 字节 zì jié
nibble/ˈnɪbl/ 半字节 bàn zì jié
memory address/ˈmeməri əˈdres/ 内存地址 nèi cún dì zhǐ
1.1

二进制加法

English

You can add two 8-bit binary numbers, column by column from the right, just like denary. The rules for one column are:

A B Result bit Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1

When a carry also comes in, $1 + 1 + 1 = 1$ with a carry of 1.

Example: add 01110110 (118) and 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-bit binary addition of 118 and 48 with the carry bits shown in red above the left columns, giving 166
Adding column by column; the carries ripple to the left. 118 + 48 = 166

Overflow

When interpreted as an unsigned integer, an 8-bit register holds values from 0 to 255. If an addition gives a result above 255, the answer needs a 9th bit. The register cannot hold this extra bit, so it is lost. This is called overflow 溢出 (an overflow error). It happens when a value goes outside the limit the register can store.

Example: 11001000 (200) $+$ 01001000 (72) $= 272$. In binary that is 1 00010000, which needs 9 bits. The leading 1 will not fit in 8 bits, so the stored answer is wrong.

Adding 200 and 72 gives 272, which in binary needs nine bits; the eight-bit register keeps only the lower eight and loses the ninth bit, so the stored answer is 16 not 272
Adding 200 and 72 needs 9 bits, but an 8-bit register drops the ninth, so the answer is wrong
词汇 训练
English 中文 拼音
overflow/ˌəʊvəˈfləʊ/ 溢出 yì chū
1.1

逻辑二进制移位

English

A logical binary shift 逻辑二进制移位 moves all the bits left or right by a number of places.

  • Bits that move off the end of the register are lost.
  • Zeros are added at the empty end.

For an unsigned integer, a left shift multiplies by 2 for each place moved if no non-zero bit is lost. A logical right shift gives the whole-number result of division by 2 for each place; the right-most bits (the least significant bit(s) 最低有效位) are lost.

Example: left shift 00110101 (53) by 2 places.

start:         0 0 1 1 0 1 0 1
left shift 2:  1 1 0 1 0 1 0 0
A logical left shift of two places: arrows move each bit two columns left, the two left-most bits are lost and two zeros enter on the right
A left shift of 2: every bit moves 2 places left, the top bits are lost and zeros fill the right

The result is 11010100 (212), which is $53 \times 4$. The two left-most bits were lost and two zeros came in on the right. If a 1 is pushed off the end, that information is gone for good.

词汇 训练
English 中文 拼音
logical binary shift/ˈlɒdʒɪkl ˈbaɪnəri ʃɪft/ 逻辑二进制移位 luó jí èr jìn zhì yí wèi
least significant bit/liːst sɪɡˈnɪfɪkənt bɪt/ 最低有效位 zuì dī yǒu xiào wèi
1.1

二进制补码

English

So far the numbers were positive. Two's complement 补码 lets an 8-bit register hold negative numbers too.

In two's complement, the left-most bit (the most significant bit 最高有效位, or MSB) has a negative place value:

-128  64  32  16  8  4  2  1
  • If the MSB is 0, the number is zero or positive.
  • If the MSB is 1, the number is negative.

To make a positive number negative: write the positive binary, flip every bit (0↔1), then add 1.

Example: make $-40$.

  • $+40$ = 00101000
  • flip the bits = 11010111
  • add 1 = 11011000

So $-40$ = 11011000. Check by adding the place values: $-128 + 64 + 16 + 8 = -40$.

A two's complement 8-bit chart where the most significant bit is worth minus 128, with 11011000 highlighted to give minus 40
The most significant bit is worth −128, so 11011000 = −128 + 64 + 16 + 8 = −40

To read a negative two's complement number, just add the place values (the MSB counts as $-128$). The range of an 8-bit two's complement number is $-128$ to $+127$.

词汇 训练
English 中文 拼音
two's complement/tuːz ˈkɒmplɪmənt/ 补码 bǔ mǎ
most significant bit/məʊst sɪɡˈnɪfɪkənt bɪt/ 最高有效位 zuì gāo yǒu xiào wèi
1.2

文本、声音与图像

教学大纲
考生应能: 注释与指导
1 理解计算机如何表示文本以及字符集(包括美国信息交换标准代码 (ASCII) 和 Unicode)的用途 • 文本被转换为二进制形式以便计算机处理
• 与 ASCII 相比,Unicode 支持更大范围的字符和符号,包括不同语言的文字和表情符号
• Unicode 每个字符所需的位数多于 ASCII
2 理解计算机如何表示声音,包括采样率和采样分辨率的影响 • 通过对声波进行采样,将声音转换为二进制形式以便计算机处理
• 采样率是指每秒采集的样本数量
• 采样分辨率是指每个样本所占的位数
• 随着采样率和分辨率的提高,录音的精度和文件大小也会增加
3 理解计算机如何表示图像,包括分辨率和颜色深度的影响 • 图像是由像素组成的序列,这些像素被转换为二进制形式以便计算机处理
• 分辨率是指图像中像素的数量
• 颜色深度是指用于表示每种颜色的位数
• 随着分辨率和颜色深度的提高,图像的文件大小和质量也会增加

来源:Cambridge International 教学大纲

English

Computers store text by giving every character a number, then storing that number in binary. The set of characters a computer can use, together with their numbers, is a character set 字符集.

ASCII uses 7-bit character codes, giving $N = 2^b = 2^7 = 128$ different codes. It includes English letters, digits and common symbols; not all 128 codes are letters. Unicode represents a much greater range of characters, including different languages and emoji 表情符号.

Try it — encode a short message. This extract from ASCII gives A = 65, B = 66, C = 67 and space = 32. Write the four 7-bit groups for CAB , including its final space. Then decode the groups 1000010 1000001 1000011.

Worked answer. Look up each character, then convert its code to binary:

Character Code Seven bits
C 67 1000011
A 65 1000001
B 66 1000010
space 32 0100000

So CAB is 1000011 1000001 1000010 0100000. The second message decodes to BAC. A space has a code too; it is not an absence of stored data. The sender and receiver must use the same character-code mapping to interpret the message correctly.

ASCII has 128 seven-bit codes; the syllabus comparison uses wider Unicode codes to represent a greater range of languages and symbols. The wider row is illustrative, not a universal Unicode width.
ASCII has 128 codes. Unicode supports a much greater range; the wider row illustrates the syllabus model.

Why a larger range matters. ASCII cannot directly represent a Chinese name. Unicode includes Chinese characters as well as English characters and many other languages. For the syllabus comparison, explain that a greater range needs more distinct binary codes, requiring more bits per character than the 7-bit ASCII model.

Try it — compare stated storage models. Store the four characters CAB using (A) 7 bits per character and (B) 16 bits per character. Assume the bits are packed with no padding or extra file information. Find the text data size in each model. The 16-bit value is an assumption for this example, not a rule that all Unicode characters take 16 bits.

Worked answer. With the same number of characters, multiply by the stated bits per character:

$$S = n b = 4 \times 7\ \text{bits} = 28\ \text{bits}$$
$$S = n b = 4 \times 16\ \text{bits} = 64\ \text{bits}$$

Model B uses more storage 存储 for this example because its stated code width is larger. Use the width given in an exam question. In real files, the encoding also matters: UTF-8 stores ASCII characters in the same bytes as an ASCII file, so Unicode text does not always occupy more bytes. You do not need the detailed UTF-8 rules for this syllabus comparison.

探索

表示声音

y = a sin(bt + c)

声音是一个波;采样每秒多次记录它的高度。

词汇 训练
English 中文 拼音
character set/ˈkærɪktə set/ 字符集 zì fú jí
emoji/ɪˈməʊdʒi/ 表情符号 biǎo qíng fú hào
storage/ˈstɔːrɪdʒ/ 存储 cún chǔ
1.2

表示声音

English

A sound wave 声波 is smooth and always changing. To store it, the computer measures the height of the wave at regular moments. This is called sampling 采样, and each measurement is a sample.

A smooth sound wave with vertical lines at regular time intervals measuring its height, marking the sample interval and the amplitude
Sampling records the wave's height (amplitude) at regular moments
  • sample rate 采样率 is the number of samples taken each second (measured in Hz).
  • sample resolution 采样分辨率 is the number of bits used for each sample. The height of the wave at a sample point is its amplitude 振幅.

A higher sample rate and a higher sample resolution give a more accurate recording, but a larger file.

探索

表示声音

y = a sin(bt + c)

声音是一个波;采样每秒多次记录它的高度。

词汇 训练
English 中文 拼音
sound wave/saʊnd weɪv/ 声波 shēng bō
sampling/ˈsæmplɪŋ/ 采样 cǎi yàng
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ǜ
amplitude/ˈæmplɪtjuːd/ 振幅 zhèn fú
1.2

表示图像

English

A computer image is made of a grid of small dots called pixels 像素.

An 8 by 8 grid of pixels forming a simple coloured picture, with one square labelled as one pixel
A bitmap is a grid of pixels; the resolution is how many pixels it has
  • resolution 分辨率 is the number of pixels in the image (for example $1920 \times 1080$).
  • colour depth 颜色深度 is the number of bits used to store the colour of each pixel.

A higher resolution and a higher colour depth give a better-quality image, but a larger file.

词汇 训练
English 中文 拼音
pixel/ˈpɪksl/ 像素 xiàng sù
resolution/ˌrezəˈluːʃn/ 分辨率 fēn biàn lǜ
colour depth/ˈkʌlə depθ/ 颜色深度 yán sè shēn dù
1.3

数据存储与压缩

教学大纲
考生应能: 注释与指导
1 理解如何度量数据存储量 • 包括:– 位(bit) – 半字节(nibble) – 字节(byte) – kibibyte (KiB) – mebibyte (MiB) – gibibyte (GiB) – tebibyte (TiB) – pebibyte (PiB) – exbibyte (EiB)
• 上一级单位在当前数据存储量中的换算关系,例如:
– 1 字节包含 8 位
– 1 gibibyte 包含 1024 mebibytes
2 利用给定信息计算图像文件和声音文件的文件大小 • 答案必须使用题目指定的单位。
• 计算必须使用 1024 作为换算基数,而非 1000。
• 给定信息可能包括:
– 图像分辨率和颜色深度
– 声音采样率、量化位数(分辨率)及曲目时长
3 理解数据压缩的目的及必要性 • 压缩旨在减小文件体积。
• 其影响包括,例如:
– 降低带宽需求
– 减少存储空间需求
– 缩短传输时间
4 理解如何使用有损和无损压缩方法对文件进行压缩 • 有损压缩通过永久删除数据来减小文件体积,例如:降低分辨率或颜色深度、降低采样率或量化位数。
• 无损压缩在不永久丢失数据的前提下减小文件体积,例如:行程长度编码(RLE)。

来源:Cambridge International 教学大纲

English

Data storage is measured in the units below. A nibble is 4 bits and a byte is 8 bits; from the kibibyte upward, each unit is 1024 times the one before it (because $1024 = 2^{10}$, which fits binary).

Unit Equals
bit a single 0 or 1
nibble 4 bits
byte 8 bits
kibibyte (KiB) 1024 bytes
mebibyte (MiB) 1024 KiB
gibibyte (GiB) 1024 MiB
tebibyte (TiB) 1024 GiB
pebibyte (PiB) 1024 TiB
exbibyte (EiB) 1024 PiB
Hard-disk platters: storage is measured in bytes — knowing file size needs width × height × colour depth for images
Hard-disk platters: storage is measured in bytes — knowing file size needs width × height × colour depth for images
1.3

计算文件大小

English

Image file size (in bits) $=$ resolution $\times$ colour depth $=$ width $\times$ height $\times$ colour depth.

Example: an image is $1024 \times 1024$ pixels with a colour depth of 2 bytes ($= 16$ bits).

  • bits $= 1024 \times 1024 \times 16 = 16\,777\,216$ bits
  • bytes $= \div 8 = 2\,097\,152$ bytes
  • KiB $= \div 1024 = 2048$ KiB
  • MiB $= \div 1024 = 2$ MiB

Sound file size (in bits) $=$ sample rate $\times$ sample resolution $\times$ length in seconds.

These formulas count uncompressed data without file headers. The sound formula is for one channel; multiply by the channel count if a question specifies more channels.

Always divide by 1024 (not 1000) to change to KiB, MiB and so on. Give your answer in the unit the question asks for.

Worked example. A sound is recorded for 30 seconds at a sample rate of 8,000 Hz with a sample resolution of 16 bits. Find the file size in kibibytes (KiB).

  • bits $= 8\,000 \times 16 \times 30 = 3\,840\,000$ bits
  • bytes $= 3\,840\,000 \div 8 = 480\,000$ bytes
  • KiB $= 480\,000 \div 1024 \approx 469$ KiB
1.3

压缩

English

Compression 压缩 makes a file smaller. A smaller file:

  • uses less storage space,
  • needs less bandwidth 带宽 (the amount of data a connection can carry),
  • takes a shorter time to send (a shorter transmission 传输 time).

There are two types.

Lossless compression

Lossless 无损 compression makes the file smaller with no permanent loss of data. The original file can be rebuilt exactly.

One method is run-length encoding 行程编码 (RLE). It replaces a run of repeated values with one copy of the value and a count of how many times it repeats. For example WWWWWWWW (8 whites) is stored as "8 W". This works well when data has many repeats.

A strip of 8 white then 4 red squares compressed into the pairs 8 W and 4 R
Run-length encoding stores each run once as a count and a value

Lossy compression

Lossy 有损 compression makes the file much smaller by permanently removing some data. The removed data cannot be got back. For example:

  • reducing the resolution or colour depth of an image,
  • reducing the sample rate or sample resolution of a sound.

Use lossless when you must keep every detail (text and program files). Use lossy for photos, music and video, where a small loss of quality is worth a much smaller file.

探索

行程长度编码

观察重复符号被压缩为计数——简单的无损压缩。

词汇 训练
English 中文 拼音
compression/kəmˈpreʃn/ 压缩 yā suō
bandwidth/ˈbændwɪdθ/ 带宽 dài kuān
transmission/trænˈsmɪʃn/ 传输 chuán shū
lossless/ˈlɒsləs/ 无损 wú sǔn
run-length encoding/rʌn leŋθ enˈkəʊdɪŋ/ 行程编码 xíng chéng biān mǎ
lossy/ˈlɒsi/ 有损 yǒu sǔn
1.3

考试技巧

English
  • Convert denary → binary by subtracting the place values (128, 64, 32 …); binary → denary by adding the place values that hold a 1.
  • To convert to hex, group the binary into nibbles of 4 bits from the right; each nibble is exactly one hex digit.
  • Overflow happens when a result is outside the chosen representation’s range. Eight-bit unsigned integers hold 0–255; eight-bit two’s complement holds −128–127.
  • File size in bits: for an image, width × height × colour depth; for sound, sample rate × resolution × seconds. Divide by 8 for bytes, then by 1024 for each larger unit.
  • Lossless compression keeps every bit (text; run-length encoding); lossy permanently removes data (photos, music) for a much smaller file.

该知识点的互动课程

逐步完成,配合即时检查练习。

历年真题

更多 IGCSE 计算机科学 知识点

登录或创建账户

IGCSE, A-Level & AP