A-Level Computer Science: Calculation Practice | A-Level 计算机:计算题专项训练

📚 A-Level Computer Science: Calculation Practice | A-Level 计算机:计算题专项训练

A-Level Computer Science exams regularly feature calculation questions that test your ability to apply binary arithmetic, Boolean logic, processor metrics, data representation, and error detection. This article delivers focused drills with step-by-step worked examples for the most common calculation topics on the syllabus. Each section presents the concept in English first, followed immediately by its Chinese equivalent, helping bilingual learners master both the technique and the terminology.

A-Level 计算机科学考试中经常出现计算类题目,考查二进制算术、布尔逻辑、处理器指标、数据表示和差错检测等核心技能。本文聚焦高频计算题型,通过详细的步骤示例进行专项训练。每个小节先以英文讲解概念与步骤,紧接着给出对应的中文解释,帮助双语学习者同时掌握解题技巧和专业术语。


1. Number System Conversions | 数制转换

Converting between decimal, binary, and hexadecimal is essential. The method of successive division by the base gives the binary equivalent of a decimal integer, with remainders read from bottom to top. For hexadecimal, group binary digits into nibbles of four.

在十进制、二进制和十六进制之间相互转换是基本功。用除基取余法可将十进制整数转为二进制,余数从下往上读取。转十六进制时,将二进制位每四位一组转换为对应的十六进制符号。

Example: Convert 21910 to binary and to hexadecimal.

例题:将 21910 转为二进制和十六进制。

Step 1: 219 ÷ 2 = 109 remainder 1

步骤1:219 ÷ 2 = 109 余 1

Step 2: 109 ÷ 2 = 54 remainder 1

步骤2:109 ÷ 2 = 54 余 1

Step 3: 54 ÷ 2 = 27 remainder 0

步骤3:54 ÷ 2 = 27 余 0

Step 4: 27 ÷ 2 = 13 remainder 1

步骤4:27 ÷ 2 = 13 余 1

Step 5: 13 ÷ 2 = 6 remainder 1

步骤5:13 ÷ 2 = 6 余 1

Step 6: 6 ÷ 2 = 3 remainder 0

步骤6:6 ÷ 2 = 3 余 0

Step 7: 3 ÷ 2 = 1 remainder 1

步骤7:3 ÷ 2 = 1 余 1

Step 8: 1 ÷ 2 = 0 remainder 1

步骤8:1 ÷ 2 = 0 余 1

Reading remainders upwards gives the binary value. In hexadecimal, group the binary as 1101 1011, giving D B.

从下往上读取余数得到二进制值。十六进制中,将二进制分组为 1101 1011,得到 D B。

21910 = 110110112 = DB16


2. Binary Addition and Overflow | 二进制加法与溢出

Binary addition follows the same rules as decimal addition: 0+0=0, 0+1=1, 1+0=1, 1+1=0 with a carry of 1 to the next column. When adding two n-bit signed numbers in two’s complement, overflow occurs if the carry into the sign bit differs from the carry out of the sign bit.

二进制加法规则与十进制类似:0+0=0, 0+1=1, 1+0=1, 1+1=0 并向高位进1。当两个 n 位补码有符号数相加时,若符号位的进位输入与进位输出不同,则发生溢出。

Example: Add the 8-bit two’s complement numbers 01101001 (105) and 00111010 (58) and determine whether overflow occurs.

例题:将 8 位补码数 01101001 (105) 与 00111010 (58) 相加,并判断是否溢出。

01101001
+ 00111010
= 10100011

Carry into sign bit (bit 7) = 1, carry out of sign bit = 0. Since they differ, overflow has occurred. The result 10100011 in two’s complement is -93, which is not 105+58, confirming overflow.

符号位(第7位)的进位输入 = 1,进位输出 = 0。二者不同,因此发生了溢出。结果 10100011 在补码中表示 -93,并非 105+58,证实了溢出。


3. Two’s Complement Range and Conversion | 补码范围与转换

Two’s complement is the standard way to represent signed integers. An n-bit two’s complement number ranges from -2ⁿ⁻¹ to 2ⁿ⁻¹ – 1. To obtain the negative of a number, invert all bits and add 1.

补码是表示有符号整数的标准方法。一个 n 位补码数的范围是从 -2ⁿ⁻¹ 到 2ⁿ⁻¹ – 1。求某数相反数时,将所有位取反后加 1。

Example: Using 8 bits, represent -27 in two’s complement and state the range of 8-bit two’s complement numbers.

例题:用 8 位补码表示 -27,并说明 8 位补码的表示范围。

First write +27 in 8-bit binary: 00011011. Invert bits → 11100100. Add 1 → 11100101. So -27 = 11100101. The range for 8-bit two’s complement is -2⁷ to 2⁷ – 1, i.e., -128 to +127.

首先写出 +27 的 8 位二进制:00011011。取反 → 11100100。加 1 → 11100101。因此 -27 = 11100101。8 位补码范围是 -2⁷ 到 2⁷ – 1,即 -128 到 +127。

-2710 = 111001012 (8-bit two’s complement)


4. Floating Point Binary Representation | 浮点二进制表示

A binary floating point number consists of a mantissa and an exponent. In a normalized representation, the mantissa’s first bit after the sign is the opposite of the sign bit for positive numbers (or the same for negative) to maximise precision. The value is mantissa × 2exponent.

二进制浮点数由尾数和阶码组成。在规范化表示中,正数尾数在符号位之后的第一位应与符号位相反(负数则相同),以最大化精度。数值 = 尾数 × 2阶码

Example: A 12-bit floating point format uses 8 bits for the mantissa and 4 bits for the exponent, both in two’s complement. Interpret the binary word 01101010 0011.

例题:某个 12 位浮点格式使用 8 位尾数和 4 位阶码,均采用补码。解读二进制字 01101010 0011。

Mantissa: 0.1101010₂ = + (1×2⁻¹ + 1×2⁻² + 0×2⁻³ + 1×2⁻⁴ + 0×2⁻⁵ + 1×2⁻⁶ + 0×2⁻⁷) = 0.5 + 0.25 + 0.0625 + 0.015625 = 0.828125. Exponent: 0011₂ = +3. Value = 0.828125 × 2³ = 6.625. In binary scientific notation: 1.10101 × 2²? Wait, we trust the given format. Mantissa is interpreted as fixed-point fraction. The result: 0.828125 × 8 = 6.625.

尾数:0.1101010₂ = + (1×2⁻¹ + 1×2⁻² + 0×2⁻³ + 1×2⁻⁴ + 0×2⁻⁵ + 1×2⁻⁶ + 0×2⁻⁷) = 0.5 + 0.25 + 0.0625 + 0.015625 = 0.828125。阶码:0011₂ = +3。数值 = 0.828125 × 2³ = 6.625。

0.11010102 × 20011₂ = 6.62510


5. Boolean Algebra Simplification | 布尔代数化简

Boolean algebra uses laws such as identity, complement, commutative, distributive, and absorption to reduce logic expressions. Simplifying expressions reduces the number of gates in a circuit.

布尔代数利用恒等律、互补律、交换律、分配律和吸收律等定律化简逻辑表达式。化简表达式可以减少电路中逻辑门的数量。

Example: Simplify F = A’B + AB + A’B’.

例题:化简 F = A’B + AB + A’B’。

Step 1: Group AB + A’B = B(A + A’) = B · 1 = B.

步骤1:组合 AB + A’B = B(A + A’) = B · 1 = B。

Step 2: Now F = B + A’B’. This cannot be simplified further by combining terms. However, apply consensus or note it is already minimal. Alternatively, use a Karnaugh map to verify. The simplified expression is B + A’B’.

步骤2:现在 F = B + A’B’。该项不能再进一步组合化简,或者可以通过卡诺图验证。化简结果为 B + A’B’。

F = B + A’B’


6. Karnaugh Map Minimisation | 卡诺图化简

A Karnaugh map (K-map) provides a visual method for simplifying Boolean expressions of up to four variables. Adjacent cells differ by only one variable, allowing grouping of 1s in sizes of powers of two to produce minimal sum-of-products expressions.

卡诺图提供了一种可视化方法,可化简最多四个变量的布尔表达式。相邻单元格之间仅有一个变量不同,因此可以将值为 1 的单元格按 2 的幂次方分组,得出最简积之和表达式。

Example: Simplify F(A, B, C) = Σ(0, 2, 4, 6) using a 3-variable K-map.

例题:用三变量卡诺图化简 F(A, B, C) = Σ(0, 2, 4, 6)。

A’B’C’ : 1 A’B’C : 0 A’BC : 0 A’BC’ : 1
AB’C’ : 1 AB’C : 0 ABC : 0 ABC’ : 1

The ones appear in cells where A=0, C=0 regardless of B (group of four) and A=1, C=0 regardless of B (another group of four). These groups correspond to A’C’ and AC’. The simplified function is F = C’.

值为 1 的单元格出现在 A=0, C=0 无论 B(四个一组)以及 A=1, C=0 无论 B(另一组四个)。这些分组对应 A’C’ 和 AC’。化简后的函数为 F = C’。

F = C’


7. Logic Gate Circuit Analysis | 逻辑门电路分析

Given a combinational logic diagram, you can derive the Boolean expression by tracing each gate’s output from inputs to final output. Then evaluate the expression for given input combinations or create a truth table.

给定一个组合逻辑电路图,可以从输入到输出依次推导每个门的输出,得出布尔表达式。然后根据给出的输入组合求值,或列出真值表。

Example: A circuit has inputs A, B. The first gate is a NAND gate with output X = (A·B)’. The second gate is a NOR gate taking X and B, so output F = (X + B)’. Find F when A=1, B=0.

例题:某电路输入为 A、B。第一个门为与非门,输出 X = (A·B)’。第二个门为或非门,输入为 X 和 B,输出 F = (X + B)’。求 A=1, B=0 时的 F。

Compute X: (1·0)’ = (0)’ = 1. Then F = (1 + 0)’ = (1)’ = 0. So output is 0.

计算 X:(1·0)’ = (0)’ = 1。然后 F = (1 + 0)’ = (1)’ = 0。因此输出为 0。

F = 0 for A=1, B=0


8. Processor Performance Calculation | 处理器性能计算

CPU performance metrics include execution time, average CPI (cycles per instruction), and MIPS (million instructions per second). Execution time = (Instruction count × CPI) / Clock rate. MIPS = (Clock rate) / (CPI × 10⁶).

CPU 性能指标包括执行时间、平均 CPI(每条指令周期数)和 MIPS(每秒百万条指令)。执行时间 = (指令数 × CPI) / 时钟频率。MIPS = (时钟频率) / (CPI × 10⁶)。

Example: A program executes 3 × 10⁸ instructions on a 2 GHz processor. The instruction mix is: 40% ALU (CPI=1), 30% load/store (CPI=2), 20% branch (CPI=3), 10% jump (CPI=2). Find the average CPI and total execution time.

例题:一个程序在 2 GHz 处理器上执行 3×10⁸ 条指令。指令分布为:40% ALU(CPI=1),30% 加载/存储(CPI=2),20% 分支(CPI=3),10% 跳转(CPI=2)。求平均 CPI 和总执行时间。

Average CPI = 0.4×1 + 0.3×2 + 0.2×3 + 0.1×2 = 0.4 + 0.6 + 0.6 + 0.2 = 1.8. Clock rate = 2×10⁹ Hz. Execution time = (3×10⁸ × 1.8) / (2×10⁹) = (5.4×10⁸) / (2×10⁹) = 0.27 seconds.

平均 CPI = 0.4×1 + 0.3×2 + 0.2×3 + 0.1×2 = 0.4 + 0.6 + 0.6 + 0.2 = 1.8。时钟频率 = 2×10⁹ Hz。执行时间 = (3×10⁸ × 1.8) / (2×10⁹) = (5.4×10⁸) / (2×10⁹) = 0.27 秒。

Avg CPI = 1.8, Execution time = 0.27 s


9. Checksum and Parity Bit Calculation | 校验和与奇偶校验位计算

Parity bits and checksums are simple error-detection methods. An even parity bit is added so that the total number of 1s in the data plus parity bit is even. A checksum is calculated by summing data bytes (often using one’s complement addition) and appending the complement of the sum.

奇偶校验位和校验和是简单的差错检测方法。偶校验位使数据位加上校验位后 1 的总数为偶数。校验和通过对数据字节求和(常采用反码加法)并附加其补码来生成。

Example (parity): Data byte 1011001 (7 bits). Add an even parity bit as the 8th bit.

例题(奇偶校验):数据字节 1011001(7 位)。添加一个偶校验位作为第 8 位。

Number of 1s = 1+0+1+1+0+0+1 = 4 (even). Even parity bit should be 0 to keep total even. So transmitted byte = 01011001 (if parity bit is placed at MSB).

1 的个数 = 4(偶数)。偶校验位应为 0 以保持总数为偶数。因此发送字节 = 01011001(假设校验位放在最高位)。

Example (checksum): Two 8-bit data bytes: 01010011 and 01101100. Calculate the simple sum (ignore overflow) and form the checksum byte.

例题(校验和):两个 8 位数据字节:01010011 和 01101100。计算简单和(忽略溢出)并构成校验和字节。

01010011
+ 01101100
= 10111111

One’s complement sum (wrap carry) might be used, but assuming simple addition, the checksum is the two’s complement of the sum, i.e., invert and add 1: 10111111 → 01000000 + 1 = 01000001. Thus checksum byte = 01000001.

如果采用简单加法,校验和为和的补码,即取反加1:10111111 → 01000000 + 1 = 01000001。因此校验和字节为 01000001。


10. Multimedia File Size Calculation | 多媒体文件大小计算

Calculating the size of image and sound files is a common exam task. For a bitmap image, file size = width × height × colour depth (bits). For uncompressed audio, size = sample rate × sample resolution × number of seconds × number of channels.

计算图像和声音文件的大小是考试常见题型。对于位图,文件大小 = 宽度 × 高度 × 色深(比特)。对于未压缩音频,大小 = 采样率 × 采样精度 × 秒数 × 声道数。

Example (image): A 1024 × 768 image uses 24-bit colour. Express the file size in MB.

例题(图像):一个 1024×768 的图像使用 24 位色彩。以 MB 表示文件大小。

Total bits = 1024 × 768 × 24 = 18,874,368 bits. Convert to bytes: ÷ 8 = 2,359,296 bytes. Convert to MB: ÷ (1024 × 1024) ≈ 2.25 MB.

总比特数 = 1024 × 768 × 24 = 18,874,368 bit。转为字节:÷ 8 = 2,359,296 B。转为 MB:÷ (1024²) ≈ 2.25 MB。

Example (audio):

Published by TutorHao | A-Level Computer Science Revision Series | aleveler.com

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

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading