← 返回资讯屏轩教育 · 行业资讯

Binary Revision for A-Level Computer Science | 二进制考点精讲

2026-07-13 20:04 · 本文部分内容由AI辅助创作

📚 Binary Revision for A-Level Computer Science | 二进制考点精讲

Binary is the language of computers. Every operation, from simple arithmetic to complex data processing, relies on sequences of 0s and 1s. In A‑Level Computer Science, you need to master binary conversions, signed number representation, floating‑point encoding, bitwise logic, and character codes. This guide covers the core concepts with worked examples to help you tackle any exam question.

二进制是计算机的语言。从简单的算术运算到复杂的数据处理,一切操作都依赖于由0和1构成的序列。在 A‑Level 计算机科学中,你需要熟练掌握二进制转换、有符号数表示、浮点数编码、位逻辑运算以及字符编码。本文通过核心概念和演示范例,帮助你攻克所有考试题型。


1. Number Systems Overview | 数制概述

Number systems define how we write values using a fixed base. Computers use base‑2 (binary), humans prefer base‑10 (decimal), and programmers often use base‑16 (hexadecimal) as a compact shorthand. Understanding the relationship between these systems is fundamental to all digital electronics and software.

数制定义了用固定基数表示数值的方式。计算机使用基数为 2 的二进制,人类习惯基数为 10 的十进制,而程序员常用基数为 16 的十六进制作为紧凑的简写形式。理解这些数制之间的关系是所有数字电子学和软件的基础。

Each digit position carries a weight that is a power of the base. For example, the binary number 1101₂ ich equals 13₁₀. Moving from binary to larger bases reduces the length of numbers, making them easier to read and debug.

每一位的位置权重是基数的幂。例如,二进制数 1101₂ 展开为 1×2³ + 1×2² + 0×2¹ + 1×2⁰,等于 13₁₀。从二进制转向更大的基数可以缩短数字长度,便于阅读和调试。


2. Binary to Decimal Conversion | 二进制转十进制

To convert a binary integer to decimal, sum the place values where a 1 appears. Place values are powers of two, increasing from right to left starting at 2⁰. This method works for any length of binary digits.

将二进制整数转换为十进制,需要将出现 1 的位置的权值相加。权值是 2 的幂,从右向左依次递增,起始为 2⁰。该方法适用于任意长度的二进制数。

101101₂ = 1×2⁵ + 0×2⁴ + 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 32 + 8 + 4 + 1 = 45₁₀

add 1 → 11; double to 22, add 0 → 22; double to 44, add 1 → 45. This is the same as Horner's method and is very efficient on paper.

一种快速心算技巧:将当前累加值翻倍,然后加上下一个比特。从 0 开始,翻倍得 0,加 1 → 1;翻倍得 2,加 0 → 2;翻倍得 4,加 1→ 5;翻倍得 10,加 1→ 11;翻倍得 22,加 0→ 22;翻倍得 44,加 1→ 45。这与霍纳法则相同,在纸上计算非常高效。


3. Decimal to Binary Conversion | 十进制转二进制

The standard technique is repeated division by 2. Write down the remainder at each step (0 or 1), then read the remainders from bottom to top. Continue dividing the quotient until it becomes zero.

标准方法是重复除以 2。记录每一步的余数(0 或 1),然后从下往上读取余数。持续除以商,直到商变为零。

7 ÷ 2 = 3 remainder 1; 3 ÷ 2 = 1 remainder 1; 1 ÷ 2 = 0 remainder 1. Reading upwards gives 11101₂. You can verify: 16+8+4+0+1 = 29.

示例:将 29₁₀ 转换为二进制。29 ÷ 2 = 14 余 1;14 ÷ 2 = 7 余 0;7 ÷ 2 = 3 余 1;3 ÷ 2 = 1 余 1;1 ÷ 2 = 0 余 1。向上读取得到 11101₂。验算:16+8+4+0+1 = 29。

011₂. Not all decimal fractions produce a finite binary expansion, which leads to rounding errors in floating‑point arithmetic.

对于小数部分,重复乘以 2 并记录整数部分(0 或 1)。0.375 × 2 = 0.75 → 0;0.75 × 2 = 1.5 → 1;0.5 × 2 = 1.0 → 1。因此 0.375₁₀ = 0.011₂。并非所有十进制小数都能产生有限的二进制展开,这会导致浮点运算中的舍入误差。


4. Hexadecimal Numbers | 十六进制数

Hexadecimal uses digits 0–9 and letters A–F to represent values 10–15. One hex digit corresponds exactly to four binary bits (a nibble). This makes conversion between binary and hex trivial: group binary digits into nibbles from the right, then replace each group with its hex equivalent.

十六进制使用数字 0–9 和字母 A–F 表示数值 10–15。一个十六进制位恰好对应四个二进制位(一个半字节)。这使得二进制与十六进制之间的转换非常简单:从右侧开始将二进制位分成四位一组,然后将每组替换为对应的十六进制值。

Binary (4 bits)HexadecimalDecimal
000000
000111
001022
.........
1010A10
1011B11
1100C12
1101D13
1110E14
1111F15

To convert 10111101₂ to hex, split into nibbles 1011 and 1101 → B and D → BD₁₆. To convert hex to binary, expand each hex digit into its 4‑bit binary form. 3F₁₆ becomes 0011 1111 → 00111111₂. In A‑Level exams, hex appears in memory dumps, colour codes, and MAC addresses.

要将 10111101₂ 转换为十六进制,分成半字节 1011 和 1101 → B 和 D → BD₁₆。将十六进制转换为二进制时,将每个十六进制位展开为 4 位二进制形式。3F₁₆ 变为 0011 1111 → 00111111₂。在 A‑Level 考试中,十六进制常出现在内存转储、颜色代码和 MAC 地址中。


5. Binary Arithmetic: Addition and Subtraction | 二进制算术:加法和减法

+0=0, 0+1=1, 1+0=1, 1+1=0 carry 1. When three bits add (including carry), 1+1+1=1 carry 1.

二进制加法遵循与十进制加法相同的规则,当一列的和超过 1 时产生进位 1。四种基本情况是:0+0=0,0+1=1,1+0=1,1+1=0 进位 1。当三个比特相加(包括进位)时,1+1+1=1 进位 1。

1011₂ (11₁₀)
+ 0110₂ ( 6₁₀)
------
10001₂ (17₁₀)

Subtraction can be performed directly or by using two's complement addition. In A‑Level syllabuses, subtraction by adding the two's complement is the preferred method because it uses the same adder hardware. To compute A − B, take the two's complement of B and add it to A. If a carry‑out beyond the most significant bit occurs, discard it (in fixed‑width registers).

减法可以直接进行,也可以利用补码加法来实现。在 A‑Level 考纲中,通过加补码来做减法是首选方法,因为它使用相同的加法器硬件。要计算 A − B,取 B 的补码然后与 A 相加。如果产生了超出最高位的进位,则丢弃它(在定宽寄存器中)。

Example: 7₁₀ − 4₁₀ using 4‑bit two's complement. 7 is 0111, 4 is 0100. Two' of 0100 is 1100. Add: 0111 + 1100 = 1 0011. Discard carry, result is 0011 = 3₁₀. Correct.

示例:使用 4 位补码计算 7₁₀ − 4₁₀。7 是 0111,4 是 0100。0100 的补码是 1100。相加:0111 + 1100 = 1 0011。丢弃进位,结果为 0011 = 3₁₀。正确。


广告 / Sponsored

6. Signed Numbers: Sign‑Magnitude, One's Complement, Two's Complement | 有符号数:原码、反码、补码

A‑ r Science examines three ways to represent signed integers in a fixed number of bits. Sign‑ tive) and the remaining bits for magnitude. It has two zeros (+0 and −0), which is inefficient. One's complement flips all bits to negate a number; it also suffers from dual zeros. Two' minant scheme in modern computers because it has a unique zero and simplifies subtraction.

A‑Level 计算机科学研究在固定位数中表示有符号整数的三种方法。原码用最高位表示符号(0 = 正,1 = 负),其余位表示数值。它有两个零(+0 和 −0),效率低下。反码通过翻转所有位来取反一个数;它也存在双零问题。补码是现代计算机中的主要方案,因为它具有唯一的零并且简化了减法。

To obtain the two's complement of a binary number: invert all bits (one' complement) and then add 1 to the least significant bit. For example, to represent −2 in 4‑bit two' t acts as a sign indicator and carries a negative weight: −2³ + 2² + 2¹ = −8 + 4 + 2 = −2.

要获取一个二进制数的补码:先将所有位取反(反码),然后在最低位加 1。例如,用 4 位补码表示 −2:+2 是 0010,取反为 1101,加 1 → 1110。最高位既是符号位,也带有负的权重:−2³ + 2² + 2¹ = −8 + 4 + 2 = −2。

Two's complement representation has a unique representation for zero (all zeros), and the range is asymmetric: for n bits, values go from −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1. For 8 bits, that is −128 to +127.

补码表示法对零有唯一的表示(全零),其取值范围不对称:对于 n 位,范围从 −2ⁿ⁻¹ 到 2ⁿ⁻¹ − 1。对于 8 位,即 −128 到 +127。


7. Two's Complement Range and Overflow | 补码范围与溢出

When the result of an addition or subtraction exceeds the representable range of the given number of bits, an overflow occurs. Overflow can be detected by examining the carry into and out of the sign bit. If the carries differ, the result is incorrect in two's complement.

当加法或减法的结果超出给定位数所能表示的范围时,就会发生溢出。可以通过检查符号位的进位输入和进位输出来检测溢出。如果这两个进位不同,则补码结果不正确。

For 4‑bit numbers, adding 5 (0101) and 4 (0100) yields 1001, which in two's complement is −7, not +9. Here, the carry into sign bit is 1, carry out is 0 — they differ, so overflow. Similarly, adding two large negative numbers can cause overflow in the negative direction.

对于 4 位数字,5(0101)加 4(0100)得到 1001,在补码中表示 −7 而非 +9。这里符号位的进位输入为 1,进位输出为 0 — 二者不同,因此溢出。类似地,两个大的负数相加也可能导致负向溢出。

When performing subtraction using two's complement, the same overflow rule applies. Understanding overflow is crucial for programming in low‑level languages where limited‑width registers are used.

在使用补码进行减法时,同样的溢出规则适用。理解溢出对于使用有限宽度寄存器的低级语言编程至关重要。


8. Fixed‑Point and Floating‑Point Representation | 定点与浮点表示

Real numbers can be stored in binary as fixed‑point or floating‑point. Fixed‑ t and a set number for the fractional part. It is simple but lacks dynamic range. Floating‑ , based on scientific notation, stores a number as mantissa × 2^exponent, allowing a trade‑off between range and precision.

实数可以以定点或浮点形式存储在二进制中。定点数为整数部分和小数部分分别预留固定数量的比特。它简单但缺乏动态范围。浮点表示基于科学记数法,将数字存储为 尾数 × 2^指数,从而可以在范围与精度之间进行权衡。

In A‑Level exams, you may be given a format with a certain number of bits for mantissa and exponent, both in two's complement. For example, an 8‑bit format with 4‑bit mantissa and 4‑bit exponent. To decode, first interpret the exponent as a two's complement integer, then shift the binary point of the mantissa accordingly. Normalised floating‑point numbers have a mantissa that starts with 01 or 10 (for positive/negative), which maximises precision.

在 A‑Level 考试中,可能会给定位数分配给尾数和指数,均使用补码。例如,一个 8 位格式,4 位尾数和 4 位指数。解码时,先将指数解释为补码整数,然后相应地移动尾数的小数点。规格化浮点数的尾数以 01 或 10 开头(分别对应正/负),以最大化精度。

Steps to convert a decimal fraction to binary floating‑point: convert the number to binary fixed‑ 11.1, normalise to 0.111 × 2², giving mantissa 0111 and exponent 0010 in a simple format.

将十进制小数转换为二进制浮点数的步骤:先将数字转换为二进制定点,然后通过移动小数点进行规格化,直到尾数以 01 或 10 开头,再编码指数。对于 3.5₁₀,二进制为 11.1,规格化得到 0.111 × 2²,在简单格式中尾数为 0111,指数为 0010。


9. Bitwise Operations | 位运算

Bitwise operators act on individual bits of binary numbers and are fundamental in low‑level programming and digital logic. The common operations are AND, OR, NOT, and XOR (exclusive OR). Masking uses AND to clear selected bits, OR to set bits, and XOR to toggle bits. Shifts move bits left or right. A logical shift left fills the vacated bit with 0; a logical shift right fills with 0. An arithmetic shift right preserves the sign bit (fills with the sign bit), useful for dividing signed numbers by powers of two.

位运算符作用于二进制数的各个比特,是低级编程和数字逻辑的基础。常见的运算包括 AND(与)、OR(或)、NOT(非)和 XOR(异或)。掩码操作使用 AND 清除选中的位,OR 置位,XOR 翻转位。移位操作将比特向左或向右移动。逻辑左移在空出的位填入 0;逻辑右移填入 0。算术右移保留符号位(用符号位填充),适用于将带符号数除以 2 的幂。

a logical shift left by 1 yields 0100 1100 (76 in unsigned interpretation, but overflow may have occurred). Arithmetic shift right on 1111 1110 (−2 in 8‑bit two' 1 1111 (−1), which is the correct division by 2 with truncation towards negative infinity.

例如,若 A = 1010 0110 (166₁₀),逻辑左移 1 位得到 0100 1100(无符号解释为 76,但可能发生溢出)。对 1111 1110(8 位补码表示 −2)进行算术右移得到 1111 1111(−1),这是向负无穷截断的正确除以 2 结果。


10. Character Encoding: ASCII and Unicode | 字符编码:ASCII 与 Unicode

Characters are stored as binary codes. ASCII is a 7‑bit code representing 128 characters, including letters, digits, and control characters. Extended ASCII uses 8 bits, providing an additional 128 codes for symbols and accented letters. Unicode is a superset that can represent virtually every writing system. UTF‑8 is a variable‑length encoding that is backward‑compatible with ASCII: the first 128 codes match ASCII and use 1 byte, while other characters require 2 to 4 bytes.

字符以二进制编码的形式存储。ASCII 是一种 7 位编码,表示 128 个字符,包括字母、数字和控制字符。扩展 ASCII 使用 8 位,提供了另外 128 个代码用于符号和重音字母。Unicode 是一个超集,几乎可以表示所有书写系统。UTF‑8 是一种可变长度编码,与 ASCII 向后兼容:前 128 个代码与 ASCII 一致,使用 1 个字节,而其他字符需要 2 至 4 个字节。

ex ASCII codes, or explain why Unicode is needed for international applications. Know that 'A' = 65₁₀ = 41₁₆ = 0100 0001₂, and 'a' difference of 32 between uppercase and lowercase letters can be flipped by toggling bit 5.

在考试题中,可能需要完成字符与二进制/十六进制 ASCII 码之间的转换,或者解释为何国际化应用需要 Unicode。要知道 'A' = 65₁₀ = 41₁₆ = 0100 0001₂, 'a' = 97₁₀ = 61₁₆ = 0110 0001₂。大小写字母之间 32 的差值可以通过翻转第 5 位来实现。


11. Binary in Computer Hardware (Registers, Memory) | 计算机硬件中的二进制(寄存器、内存)

All modern computers use binary to store instructions and data. Memory is organised as a sequence of addressable locations, each holding a fixed number of bits (typically 8 bits per byte). Registers inside the CPU, such as the accumulator, program counter, and instruction register, all hold binary patterns. The data bus, address bus, and control bus carry binary signals between components.

所有现代计算机都使用二进制来存储指令和数据。内存被组织为一系列可寻址的位置,每个位置保存固定数量的比特(通常每字节 8 位)。CPU 内部的寄存器,如累加器、程序计数器和指令寄存器,都持有二进制模式。数据总线、地址总线和控制总线在组件之间传输二进制信号。

Binary is also used to represent machine code instructions. An opcode followed by an operand is just a binary number decoded by the control unit. This is why understanding binary, hex, and bitwise operations is essential for anyone studying processor architecture.

二进制也用于表示机器码指令。操作码后面跟着操作数,本质上就是一个由控制单元解码的二进制数。这就是为什么学习处理器体系结构的人必须理解二进制、十六进制和位运算。


12. Practice and Common Exam Questions | 练习与常见考题

A‑Level binary questions often combine several topics. You may be asked to convert a negative decimal to two's complement in a given number of bits, add two binary numbers and comment on overflow, or interpret a floating‑point binary as a decimal value. Applying a systematic method is the key to avoiding careless mistakes.

A‑Level 二进制考题通常综合多个主题。你可能需要将负数十进制转换为给定位数的补码,将两个二进制数相加并评论溢出情况,或者将浮点二进制解释为十进制值。应用系统化的方法是避免粗心错误的关键。

Practise with past papers and write your answers clearly using the subscript notation (₂, ₁₀, ₁₆) to avoid ambiguity.

利用往年真题进行练习,并使用下标符号(₂, ₁₀, ₁₆)清晰地书写答案,以避免歧义。

Published by TutorHao | Computer Science Revision Series | aleveler.com

广告 / Sponsored
现货 Cambridge International AS & ALevel IT Coursebook剑桥国际IGC…
计算机 备考教辅 · 正版现货 · 与本文内容相关
查看详情 / View on Taobao参考价 ¥467.0

更多咨询请联系16621398022(同微信)

备考资讯每日更新,关注不错过
考纲变化 · 科目分析 · 学习方法
扫码关注公众号 tutorhao
在微信里长按二维码识别关注
或截图后用「扫一扫 → 相册」选择本图
公众号:tutorhao