📚 IB AQA Computer Science: Binary Essentials | IB AQA 计算机:二进制考点精讲
Binary is the bedrock of all modern computing. From the simplest microcontroller to the most powerful supercomputer, every piece of data and every instruction is ultimately represented as a sequence of 0s and 1s. Mastering binary is not just a requirement for your AQA IB Computer Science exam – it is the key to understanding how machines ‘think’. This article will guide you through the core concepts, conversion techniques and data representation methods that you must know for top marks.
二进制是所有现代计算的基石。从最简单的微控制器到最强大的超级计算机,每一份数据和每一条指令最终都表示为一系列 0 和 1。掌握二进制不仅是 AQA IB 计算机科学考试的要求,更是理解机器如何“思考”的关键。本文将带你逐一攻克核心概念、转换技巧以及数据表示方法,帮助你在考试中取得高分。
1. Understanding Binary – The Language of Computers | 理解二进制:计算机的语言
Computers use binary (base‑2) because their most fundamental hardware components – transistors – operate with two stable states: OFF (0) and ON (1). A single binary digit is called a bit, and a group of 8 bits is a byte. Everything stored or processed, numbers, text, images, sound, is encoded as patterns of bits. AQA expects you to explain why binary is used and to work comfortably with bit patterns up to (and often beyond) 8 bits.
计算机使用二进制(基数为 2)是因为其最基本的硬件元件——晶体管——只有两种稳定状态:关 (0) 和开 (1)。单个二进制数字称为比特 (bit),8 个比特组成一个字节 (byte)。储存或处理的所有内容——数字、文本、图像、声音——都以位模式编码。AQA 考试要求你能够解释为何使用二进制,并熟练处理高达(甚至超过)8 位的位模式。
The least significant bit (LSB) is the rightmost bit, having the smallest weight (2⁰), while the most significant bit (MSB) is the leftmost bit. When writing binary numbers we often group bits into nibbles (4 bits) to improve readability, for example 1010 1110₂. Subscript ‘2’ indicates binary; denary (decimal) is often written without a subscript or with subscript ‘10’.
最低有效位 (LSB) 是最右边的位,权重最小 (2⁰);最高有效位 (MSB) 是最左边的位。书写二进制数时,我们常将比特每 4 位分为一组(称为半字节 nibble)以提高可读性,例如 1010 1110₂。下标“₂”表示二进制;十进制 (denary) 通常不加下标或以下标“₁₀”表示。
2. Converting Between Binary and Denary | 二进制与十进制转换
To convert a binary number to denary, multiply each bit by its positional weight (a power of 2) and sum the products. For an 8‑bit number, the weights from left to right are 2⁷, 2⁶, 2⁵, 2⁴, 2³, 2², 2¹, 2⁰, i.e. 128, 64, 32, 16, 8, 4, 2, 1. The conversion is straightforward: 10110010₂ = 1×128 + 0×64 + 1×32 + 1×16 + 0×8 + 0×4 + 1×2 + 0×1 = 128 + 32 + 16 + 2 = 178₁₀.
将二进制数转换为十进制,需要将每一位乘以其位置权重(2 的幂)并求和。对于 8 位数字,从右到左的权重分别为 2⁰, 2¹, 2², 2³, 2⁴, 2⁵, 2⁶, 2⁷(即 1, 2, 4, 8, 16, 32, 64, 128)。转换十分直接:10110010₂ = 1×128 + 0×64 + 1×32 + 1×16 + 0×8 + 0×4 + 1×2 + 0×1 = 128 + 32 + 16 + 2 = 178₁₀。
Converting denary to binary requires successive division by 2, noting the remainders. For 178: 178 ÷ 2 = 89 remainder 0; 89 ÷ 2 = 44 r 1; 44 ÷ 2 = 22 r 0; 22 ÷ 2 = 11 r 0; 11 ÷ 2 = 5 r 1; 5 ÷ 2 = 2 r 1; 2 ÷ 2 = 1 r 0; 1 ÷ 2 = 0 r 1. Reading the remainders from bottom to top gives 10110010₂. Practice both directions until you can do them almost automatically – exam questions will mix straightforward conversion with interpretation.
将十进制转换为二进制则需要反复除以 2,记录余数。以 178 为例:178 ÷ 2 = 89 余 0;89 ÷ 2 = 44 余 1;44 ÷ 2 = 22 余 0;22 ÷ 2 = 11 余 0;11 ÷ 2 = 5 余 1;5 ÷ 2 = 2 余 1;2 ÷ 2 = 1 余 0;1 ÷ 2 = 0 余 1。从下往上读取余数即得 10110010₂。请反复练习两种方向的转换,直到近乎本能反应——考试题目会混合直接转换与意义解读。
Quick reference table for 4‑bit nibbles (0–15):
4 位半字节 (0–15) 速查表:
| Denary | Binary | Denary | Binary |
|---|---|---|---|
| 0 | 0000 | 8 | 1000 |
| 1 | 0001 | 9 | 1001 |
| 2 | 0010 | 10 | 1010 |
| 3 | 0011 | 11 | 1011 |
| 4 | 0100 | 12 | 1100 |
| 5 | 0101 | 13 | 1101 |
| 6 | 0110 | 14 | 1110 |
| 7 | 0111 | 15 | 1111 |
3. Binary Addition and Overflow | 二进制加法与溢出
Binary addition follows simple rules: 0+0=0, 0+1=1, 1+0=1, 1+1=0 carry 1, 1+1+carry 1=1 carry 1. You always add column by column from the right, just like denary addition. For example: 0110₂ (6) + 0111₂ (7) = 1101₂ (13). The examiner will expect you to show carries clearly.
二进制加法遵循简单规则:0+0=0,0+1=1,1+0=1,1+1=0 进位 1,1+1+进位 1=1 进位 1。与十进制加法一样,始终从右向左逐列相加。例如:0110₂ (6) + 0111₂ (7) = 1101₂ (13)。考官希望你能清晰地标出进位。
Overflow occurs when the result of an addition exceeds the maximum value that can be stored in the available number of bits. In an 8‑bit unsigned system, the maximum is 255 (11111111₂). Adding 1 to 255 yields 1 00000000₂ – the ninth bit cannot be stored, so the 8‑bit result is 00000000₂, which is clearly wrong. The processor typically sets an overflow flag to signal this error. AQA questions often ask you to identify overflow and explain its implications.
溢出发生在加法结果超出指定位数所能存储的最大值时。在 8 位无符号系统中,最大值是 255 (11111111₂)。255 加 1 得到 1 00000000₂——第 9 位无法存储,因此 8 位结果为 00000000₂,这显然是错误的。处理器通常会设置溢出标志来报告该错误。AQA 考题经常要求你识别溢出并说明其后果。
For two signed numbers in two’s complement, overflow can also occur if the sum of two positive numbers appears negative, or the sum of two negatives appears positive. You must be able to detect this by examining the carry into and out of the MSB.
对于两个使用补码表示的有符号数,如果两个正数之和看似为负,或两个负数之和看似为正,也会发生溢出。你必须能够通过检查进入 MSB 与离开 MSB 的进位来检测溢出。
4. Signed Binary Numbers – Sign-Magnitude and Two’s Complement | 有符号二进制数:原码与补码
To represent negative numbers, computers do not simply use a minus sign. The simplest method is sign‑magnitude: the MSB indicates the sign (0 for positive, 1 for negative) and the remaining bits hold the magnitude. For an 8‑bit number, +18 is 00010010₂, and −18 is 10010010₂. However, sign‑magnitude creates two zeros (+0 and −0) and complicates arithmetic.
为表示负数,计算机并非简单地使用负号。最简单的方法是原码:最高位表示符号(0 为正,1 为负),其余位存储数值大小。对于 8 位数,+18 是 00010010₂,−18 是 10010010₂。然而,原码会产生两个零(+0 和 −0),并使算术运算复杂化。
Two’s complement is the dominant method because it simplifies circuit design and subtraction. To obtain the two’s complement of a positive number: invert all bits (one’s complement) and then add 1. For −18: start with +18 = 00010010₂ → one’s complement 11101101₂ → add 1 → 11101110₂. To check: 00010010₂ + 11101110₂ = 1 00000000₂ (ignoring the carry out, the 8‑bit result is 0, confirming it is the correct negative). The range of an n‑bit two’s complement number is from −2ⁿ⁻¹ to 2ⁿ⁻¹−1. For 8 bits: −128 to +127.
补码是主流方法,因为它简化了电路设计和减法运算。求一个正数的补码:将所有位取反(反码),再加 1。以 −18 为例:从 +18 = 00010010₂ 开始 → 反码为 11101101₂ → 加 1 → 11101110₂。验证:00010010₂ + 11101110₂ = 1 00000000₂(忽略进位,8 位结果为 0,证明它是正确的负数)。n 位补码的表示范围为 −2ⁿ⁻¹ 至 2ⁿ⁻¹−1。对于 8 位:−128 至 +127。
Note that in two’s complement the MSB still effectively acts as a sign bit (1 for negative), but its weight is negative: −2ⁿ⁻¹. This is a key concept for AQA: you should be able to explain the weight of the MSB and convert between negative denary and two’s complement binary rapidly.
注意,在补码中,最高位仍然有效地充当符号位(1 表示负),但其权重为负:−2ⁿ⁻¹。这是 AQA 的一个关键概念:你应能解释 MSB 的权重,并在负十进制与二进制补码之间快速转换。
5. Binary Subtraction Using Two’s Complement | 使用补码进行二进制减法
Subtraction is performed by adding the two’s complement of the subtrahend. For instance, calculate 26 – 17 in 8‑bit two’s complement. 26 = 00011010₂, 17 = 00010001₂. The two’s complement of 17 is 11101111₂. Now add: 00011010₂ + 11101111₂ = 1 00001001₂. Discarding the final carry (overflow bit) leaves 00001001₂, which is +9 in denary – the correct result.
减法通过加上减数的补码来实现。例如,用 8 位补码计算 26 – 17。26 = 00011010₂,17 = 00010001₂。17 的补码是 11101111₂。现在相加:00011010₂ + 11101111₂ = 1 00001001₂。丢弃最后的进位(溢出位)得到 00001001₂,即十进制 +9——正确结果。
When the result is negative, the answer will already be in two’s complement form. For 17 – 26: 00010001₂ + (two’s complement of 00011010₂ = 11100110₂) = 11110111₂. This is a negative number because the MSB is 1. To find its denary value, take its two’s complement: invert (00001000₂) +1 = 00001001₂ (9), so the result is –9. AQA examiners love these multi‑step problems because they test your grasp of both conversion and the underlying logic.
当结果为负数时,答案本身就已经是补码形式。计算 17 – 26:00010001₂ + (00011010₂ 的补码 = 11100110₂) = 11110111₂。由于 MSB 为 1,这是一个负数。要求得其中进制值,再次求其补码:取反 (00001000₂) + 1 = 00001001₂ (9),因此结果为 –9。AQA 考官非常喜欢这类多步骤题目,因为它们能同时测试你的转换能力和对底层逻辑的理解。
6. Fixed-Point Representation | 定点数表示
Binary can represent fractions using a fixed‑point format. A binary point separates the integer part from the fractional part. For example, in a 8‑bit number with 4 integer bits and 4 fractional bits, the pattern 0110.1010₂ has integer part 0110₂ = 6 and fractional part .1010₂ = 1×½ + 0×¼ + 1×⅛ + 0×1/16 = 0.5 + 0.125 = 0.625, giving 6.625. The AQA specification expects you to convert between denary fractions and binary fixed‑point numbers with a stated number of fractional bits.
二进制可以用定点格式表示小数。二进制小数点用以分隔整数部分和小数部分。例如,在一个 4 位整数、4 位小数的 8 位数字中,模式 0110.1010₂ 的整数部分为 0110₂ = 6,小数部分为 .1010₂ = 1×½ + 0×¼ + 1×⅛ + 0×1/16 = 0.5 + 0.125 = 0.625,结果为 6.625。AQA 大纲要求你能够在十进制小数与指定小数位数的二进制定点数之间进行转换。
To convert a denary fraction to binary, repeatedly multiply the fractional part by 2 and record the integer part (0 or 1) until the fractional part becomes zero or you have enough bits. For 0.625: 0.625×2=1.25 (record 1), 0.25×2=0.5 (0), 0.5×2=1.0 (1) → .101₂. The integer part is converted normally. Fixed‑point representation is limited by the trade‑off between range and precision: more integer bits give a larger range; more fractional bits give greater precision. You may be asked to discuss this trade‑off.
将十进制小数转换为二进制,需要反复将小数部分乘以 2,记录整数部分(0 或 1),直至小数部分为零或得到足够位数。对于 0.625:0.625×2=1.25(记 1),0.25×2=0.5(记 0),0.5×2=1.0(记 1)→ .101₂。整数部分按常规方法转换。定点数表示受限于范围与精度的权衡:整数位越多,范围越大;小数位越多,精度越高。考试中可能要求你讨论这种权衡。
7. Floating-Point Representation | 浮点数表示
Very large and very small numbers are stored in floating‑point form, which is essentially binary scientific notation. A number is represented as mantissa × 2exponent. In the IEEE 754 single‑precision standard (32 bits): bit 31 is the sign bit (0 for positive, 1 for negative), bits 30–23 are the exponent stored with a bias of 127, and bits 22–0 store the mantissa (fractional part) with an implied leading 1 for normalised numbers. The value is (−1)^sign × (1.mantissa) × 2^(exponent−127).
非常大和非常小的数字以浮点数格式存储,这本质上是二进制的科学记数法。一个数表示为尾数 × 2指数。在 IEEE 754 单精度标准(32 位)中:第 31 位是符号位(0 正 1 负),第 30–23 位是以偏移量 127 存储的指数,第 22–0 位存储尾数(小数部分),规格化数隐含前导 1。数值为 (−1)^符号 × (1.尾数) × 2^(指数−127)。
Although AQA does not require full manual conversion to IEEE 754, you must understand the structure, the purpose of the bias, and the advantages of floating‑point over fixed‑point (much greater range, ability to represent very small fractions). You should also be aware of the limitations: limited precision (only about 7 decimal digits for single precision) and rounding errors that can accumulate in calculations. A typical exam question might ask you to explain why 0.1 cannot be represented exactly in binary floating‑point.
尽管 AQA 不要求完整地手工转换到 IEEE 754,但你必须理解其结构、偏移量的作用,以及浮点数相对于定点数的优势(范围大得多,能表示极小的小数)。你还应了解其局限性:精度有限(单精度约 7 位十进制有效数字)以及计算中可能累积的舍入误差。典型的考题可能会要求你解释为什么 0.1 无法用二进制浮点数精确表示。
Normalisation ensures that the mantissa’s most significant bit is 1 (for a positive number) so that no bits are wasted. For example, unnormalised 0.00101 × 2³ can be normalised to 1.01 × 2¹. In binary, this means shifting the mantissa left and reducing the exponent accordingly.
规格化确保尾数的最高有效位为 1(对于正数),从而不浪费任何位。例如,未规格化的 0.00101 × 2³ 可规格化为 1.01 × 2¹。在二进制中,这意味着将尾数左移并相应减小指数。
8. Character Encoding – ASCII and Unicode | 字符编码:ASCII 与 Unicode
Text is stored as binary numbers using agreed encoding schemes. ASCII (American Standard Code for Information Interchange) originally used 7 bits, representing 128 characters (codes 0–127), including control characters, digits, uppercase and lowercase letters, and punctuation. Extended ASCII uses 8 bits (256 characters) to include additional symbols. For example, ‘A’ is 65 (01000001₂), ‘a’ is 97 (01100001₂).
文本通过约定好的编码方案存储为二进制数字。ASCII(美国信息交换标准码)最初使用 7 位,表示 128 个字符(编码 0–127),包括控制字符、数字、大小写字母和标点。扩展 ASCII 使用 8 位(256 个字符)以包含额外符号。例如,’A’ 为 65 (01000001₂),’a’ 为 97 (01100001₂)。
Unicode was developed to handle the world’s writing systems and symbols. It assigns a unique code point (written U+0041 for ‘A’) to every character. UTF‑8, UTF‑16 and UTF‑32 are variable‑length encodings of Unicode. UTF‑8 is backward compatible with ASCII and uses 1 byte for common characters, up to 4 bytes for others. For AQA, you should know the difference between ASCII and Unicode, why Unicode is necessary, and the basic principle of variable‑length encoding.
Unicode 是为了处理世界上各种书写系统与符号而开发的。它为每个字符分配唯一的码点(如 ‘A’ 为 U+0041)。UTF‑8、UTF‑16 和 UTF‑32 是 Unicode 的变长编码方式。UTF‑8 向后兼容 ASCII,对常用字符使用 1 字节,对其他字符最多使用 4 字节。在 AQA 考试中,你需要了解 ASCII 与 Unicode 的区别、Unicode 的必要性以及变长编码的基本原理。
You may be asked to calculate the storage requirement for a text string given the encoding. For instance, a message with 100 characters in ASCII takes 100 bytes; in UTF‑8 it could be larger if it contains non‑Latin scripts. Always check the question context.
你可能会被要求根据编码计算文本字符串的存储空间需求。例如,包含 100 个字符的 ASCII 消息占用 100 字节;若使用 UTF‑8 并包含非拉丁文字,则可能占用更多字节。答题时请务必关注题目上下文。
9. Logic Operations on Binary Data | 二进制数据的逻辑运算
Processors perform bitwise logic operations on binary patterns. The fundamental gates are NOT, AND, OR and XOR. For single bits: NOT 0 = 1, NOT 1 = 0. AND: 1 AND 1 = 1, else 0. OR: 0 OR 0 = 0, else 1. XOR (exclusive OR): 1 XOR 1 = 0, 1 XOR 0 = 1 (outputs 1 only if inputs differ). These operations are applied bitwise across whole bytes, for example 10101100₂ AND 11001010₂ = 10001000₂.
处理器对二进制模式执行按位逻辑运算。基本逻辑门包括 NOT、AND、OR 和 XOR。对于单个位:NOT 0 = 1,NOT 1 = 0。AND:1 AND 1 = 1,其他为 0。OR:0 OR 0 = 0,其他为 1。XOR(异或):1 XOR 1 = 0,1 XOR 0 = 1(仅当输入不同时输出 1)。这些运算按位应用于整个字节,例如 10101100₂ AND 11001010₂ = 10001000₂。
Truth tables are essential for describing logic functions. AQA may ask you to complete a truth table for a given logic circuit or expression, or to use masking and combining operations. For instance, to set (turn on) specific bits you can OR with a mask where those bits are 1; to clear bits (turn off) you AND with a mask where those bits are 0. XOR can be used to toggle bits. Understanding these operations is crucial for low‑level programming and hardware questions.
真值表是描述逻辑功能的关键。AQA 可能会要求你为给定的逻辑电路或表达式填写真值表,或运用掩码与组合操作。例如,要设置(开启)特定位,你可以将其与掩码(对应位为 1)进行 OR 运算;要清除(关闭)特定位,则与掩码(对应位为 0)进行 AND 运算。XOR 可用于翻转位。理解这些操作对于底层编程和硬件题目至关重要。
10. Bitwise Shifts and Masking | 位移与掩码
Shifting all the bits in a register left or right has arithmetic consequences. A logical left shift by one position multiplies the unsigned value by 2 (e.g. 00000101₂ (5) shifted left becomes 00001010₂ (10)). Vacant positions are filled with 0. A logical right shift on unsigned numbers divides by 2 (discarding the fractional part). However, for signed two’s complement numbers we use an arithmetic right shift, which preserves the MSB (sign bit) by filling vacancies with a copy of the sign bit. For example, 11111000₂ (−8) arithmetically shifted right once gives 11111100₂ (−4).
将寄存器中的所有位向左或向右移动会产生算术效果。无符号数逻辑左移一位相当于乘以 2(例如 00000101₂ (5) 左移变为 00001010₂ (10))。空出的位置填充 0。无符号数的逻辑右移则相当于除以 2(舍弃小数部分)。然而,对于有符号补码数,我们使用算术右移,通过填充符号位的副本来保留 MSB(符号位)。例如,11111000₂ (−8) 算术右移一位得到 11111100₂ (−4)。
A bit mask is a pattern used to extract or modify specific bits within a byte. For example, to test whether the third bit (counting from 0) of a value is set, you could AND with 00001000₂; if the result is non‑zero the bit was set. Masks are heavily used in status registers and permission systems. You should be comfortable constructing a mask to isolate or change given bits.
位掩码是一种用来提取或修改字节中特定位的模式。例如,要测试一个值的第 3 位(从 0 开始计)是否置位,你可以与 00001000₂ 进行 AND 运算;若结果非零,则该位原为 1。掩码在状态寄存器和权限系统中被大量使用。你应当能熟练地构造掩码来隔离或更改给定的位。
Circular shifts (rotate) move bits around and feed the displaced bit back into the opposite end. They are useful in some cryptography and checksum algorithms. While AQA concentrates on logical and arithmetic shifts, knowing the concept of rotation can help you answer extension questions confidently.
循环移位(旋转)会将位移出的一端重新填入另一端。在某些密码学和校验和算法中会用到。虽然 AQA 主要关注逻辑与算术移位,但了解循环移位的概念能帮助你自信地回答拓展题。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导