Cambridge International AS & A Level Computer Science 9618 · Paper 1

Chapter 1.1 Data Representation 数据表示

从“为什么电脑只用 0 和 1”开始,逐步学习进制、BCD、补码、二进制运算、overflow、hexadecimal 应用和 character sets。适合第一次学习本章的学生。

Before you begin

同一串 bits 为什么能有不同含义?

电脑的存储器保存的是 bits。程序必须约定怎样解释这些 bits:它们可能代表一个正整数、负整数、hexadecimal value、BCD digits,甚至是一个字符。本章的核心不是只做进制转换,而是理解representation 决定 bits 的含义

考纲范围学生最终需要做到
Binary magnitudes区分 binary prefixes 与 decimal prefixes,并使用 kibi/kilo、mebi/mega、gibi/giga、tebi/tera。
Number systems使用 binary、denary、hexadecimal、BCD、one’s complement 和 two’s complement。
Conversion在不同 number base 或 representation 之间转换整数。
Arithmetic进行正数和负数的 binary addition 与 subtraction,并解释 overflow。
Applications描述 BCD 与 hexadecimal 的实际用途,并解释选择理由。
Character data解释字符怎样以内部 binary form 保存,并比较 ASCII、extended ASCII 和 Unicode。
先建立两个概念

Digit 是写在数字中的一个符号;place value 是该位置代表的权值。相同的 digits 放在不同位置,价值不同。

Stage 1

bit、byte 与 binary place value

Bit 是 binary digit,只能是 0 或 1。8 bits 组成 1 byte。硬件使用两种稳定状态表示它们,例如低电压与高电压。

Denary 是 base 10,每向左一位乘以 10;binary 是 base 2,每向左一位乘以 2。8-bit unsigned binary 的位权如下:

1286432168421 01011010
01011010 = 64 + 16 + 8 + 2 = 90

Unsigned binary 的范围

n bits 可产生 2^n 个不同组合。Unsigned representation 从 0 开始,所以最大值是 2^n - 1

8-bit unsigned range = 0 to 2⁸ - 1 = 0 to 255 12-bit unsigned range = 0 to 2¹² - 1 = 0 to 4095
Stage 2

Binary prefixes 与 decimal prefixes

存储容量中常见两套单位。Decimal prefix 每一级按 1000 变化;binary prefix 每一级按 1024,也就是 2¹⁰ 变化。

Binary prefixBytesDecimal prefixBytes
kibibyte (KiB)2¹⁰ = 1024kilobyte (kB)10³ = 1000
mebibyte (MiB)2²⁰megabyte (MB)10⁶
gibibyte (GiB)2³⁰gigabyte (GB)10⁹
tebibyte (TiB)2⁴⁰terabyte (TB)10¹²
名称必须对应

Kibi 是 binary prefix,但 mega 是 decimal prefix。题目可能故意跨级比较,例如 kibibyte 与 megabyte,不能只看首字母。

Stage 3

Binary、denary 与 hexadecimal 转换

Hexadecimal 是 base 16,使用 digits 0–9A–F。其中 A=10B=11、…、F=15

DenaryBinaryHexDenaryBinaryHex
000000810008
100011910019
200102101010A
300113111011B
401004121100C
501015131101D
601106141110E
701117151111F

Binary ↔ hexadecimal

一个 hexadecimal digit 正好对应 4 bits。Binary 从右向左每四位分组:

1101 0110 1101 = D 0110 = 6 Answer = D6

Hexadecimal → denary

Hex 的位权是 …, 16², 16¹, 16⁰

A04 = (10 × 16²) + (0 × 16¹) + (4 × 16⁰) = 2560 + 0 + 4 = 2564

Minimum number of bits

选择满足 2^n ≥ number of possible values 的最小 n。例如 256 种状态需要 8 bits;但数值 256 本身需要 9-bit unsigned binary。

Stage 4

BCD:每个 denary digit 单独编码

Binary Coded Decimal 不把整个数直接转换成 pure binary。它把每一个 denary digit 分开,并分别用 4 bits 表示。

Denary 1081 | 0 | 80001 | 0000 | 1000
BCD 的 1080001 0000 1000。Pure binary 的 108 才是 01101100

4-bit BCD 只使用 00001001 表示 0 到 9;10101111 不代表有效的单个 decimal digit。

最常见错误

先把十进制数整体转换为 binary,得到的是 pure binary,不是 BCD。看到 BCD 时必须先拆开十进制 digits。

Stage 5

One’s complement 与 two’s complement

最高位为 1 并不自动表示负数。只有题目说明采用 one’s complement 或 two’s complement 时,bits 才按对应规则解释。

One’s complement

固定 bit length 后,把每个 bit invert:0 变 1,1 变 0。

+120 = 0111 1000 −120 = 1000 0111 (invert every bit)

Two’s complement

先写出正数,并保持题目要求的 bit length。

Invert every bit。

Add 1。

+108 in 12 bits 0000 0110 1100 Invert every bit 1111 1001 0011 Add 1 1111 1001 0100 Therefore −108 1111 1001 0100

把 two’s complement 转回 denary

可把最左边的 bit 视为负权值。8-bit two’s complement 的位权是:

−128 64 32 16 8 4 2 1 1 0 0 1 1 1 1 1 10011111 = −128 + 16 + 8 + 4 + 2 + 1 = −97

n-bit two’s complement 范围为 −2^(n−1)2^(n−1)−1。8-bit 范围是 −128 到 127。

Stage 6

Binary addition 与 subtraction

加法规则

0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10 (write 0, carry 1) 1 + 1 + 1 = 11 (write 1, carry 1)

从最右位开始逐列相加。若一列的结果有两位,右边一位写在本列,左边一位作为 carry 放到下一列。

用 two’s complement 做减法

A − B 可以改写成 A + (−B):先求 B 的 two’s complement,再进行 binary addition。超过固定 bit length 的最高位 carry 可丢弃。

74 − 23 74 0100 1010 23 0001 0111 −23: invert 1110 1000 add 1 1110 1001 0100 1010 + 1110 1001 ------------ 1 0011 0011 8-bit answer = 0011 0011 = 51
Stage 7

Overflow:答案超出可表示范围

Overflow 不是“算错了”,而是正确的数学答案不能用当前可用的 bits 表示。8-bit unsigned 只能表示 0–255;8-bit two’s complement 只能表示 −128–127。

8-bit two’s complement: 0111 1111 = +127 + 0000 0001 = +1 ------------ 1000 0000 (bit pattern represents −128, not +128) Mathematical answer +128 is outside the range −128 to +127. Therefore overflow occurs.
Carry 与 overflow 不相同

Carry 是最高位产生的进位;overflow 取决于当前 representation 的范围。判断时必须先知道数据是 unsigned 还是 two’s complement。

Mark-scheme wording:The answer cannot be represented in the number of bits available.
Stage 8

为什么实际系统使用 BCD 与 hexadecimal?

BCD applications

ApplicationMatching justification
Financial / banking calculationsMonetary values can be represented exactly,避免 normal binary 中某些 decimal fractions 的 accumulating / rounding errors。
Electronic displays,例如 calculator、digital clock设备显示 individual denary digits;BCD 与 denary digits 之间转换 straightforward。
Date and time in a PC BIOS与人类使用的 denary date/time digits 转换容易。
Barcode systems每个 denary digit 可直接、准确地单独编码。

Hexadecimal applications

  • HTML colour codes,例如 #FC238A
  • Memory addresses、assembly language 与 machine code
  • MAC addresses 与 IPv6 addresses

Hexadecimal 比长串 binary 更短,更方便人类阅读、记忆和抄写。每个 hex digit 直接对应 4 bits,所以转换 straightforward。

应用题必须匹配理由

只写 “BCD is used in banking” 通常只能获得 application 分。第二分必须说明为什么该 representation 适合这个场景。

Stage 9

Character sets:用数字表示字符

Character set 是电脑可以表示的全部 characters / symbols 的集合,并且每个 character 都有一个 unique numeric or binary code

Cunique code
lunique code
ounique code
cunique code
kunique code
每个 character 分别替换成 code,再按单词中的顺序存储。电脑不是给整个单词分配一个 code。
Character set课堂理解
ASCII通常描述为 7 bits,可表示 128 个 codes;主要覆盖 Latin letters、digits、punctuation 和 control characters。
Extended ASCII8 bits,可表示 256 个 codes。
Unicode提供更大的 code range,可表示更多语言、symbols 和 emoji;ASCII characters 包含在 Unicode 中。
考纲不要求背 code

学生不需要背诵字母 A 的具体 binary code。考试重点是 unique code、stored in sequence,以及不同 character sets 的范围差异。

Final review

完成本章后的检查表

  • 我能用 place values 把 unsigned binary 转换成 denary。
  • 我能区分 binary prefixes 和 decimal prefixes。
  • 我能在 binary、denary 与 hexadecimal 之间转换。
  • 我知道 BCD 是 each denary digit separately represented by four bits。
  • 我能保持固定 bit length,完成 one’s 和 two’s complement。
  • 我能显示 carries 或 two’s complement working,完成 binary addition/subtraction。
  • 我能用 representable range 或 number of bits available 解释 overflow。
  • 我能给出 BCD/hex application,并写出与场景匹配的 justification。
  • 我能定义 character set,并解释一个 word 怎样以 codes in sequence 保存。
  • 我能比较 ASCII、extended ASCII 和 Unicode,而不依赖背具体 codes。
下一步

进入 1.1 filtered practice,在不看教材的情况下完成更多真题。计算题必须保留 working,简答题按 marks 写独立得分点。

本页练习输入会保存在当前浏览器的 local storage,不会上传到服务器。

课程依据:Cambridge International AS & A Level Computer Science 9618 syllabus for examination in 2026, section 1.1 Data Representation;以及页面标注的 2022–2025 Past Paper questions 与对应 Mark Schemes。

查看 Cambridge 官方 2026 syllabus