📚 IB & Edexcel Computer Science: Calculation Practice Drills | IB 及 Edexcel 计算机科学:计算题专项训练
Mastering calculation questions is essential for achieving top grades in IB and Edexcel Computer Science exams. This guide provides a structured drill covering the most common quantitative topics, from number base conversions and Boolean algebra to file size estimation and algorithmic efficiency. Each section pairs concise explanations with worked examples, allowing you to practise the exact skills examiners test.
掌握计算题是在IB和Edexcel计算机科学考试中取得高分的关键。本指南提供了一个结构化的专项训练,涵盖最常见的量化主题,从数制转换和布尔代数到文件大小估算和算法效率。每个小节都将简明讲解与实例相结合,帮助你精准练习考试所考查的技能。
1. Binary and Hexadecimal Conversions | 二进制与十六进制转换
Number system conversions are frequently tested. To convert a decimal integer to binary, repeatedly divide by 2 and record the remainders, reading from bottom to top. For hexadecimal, divide by 16; remainders greater than 9 are represented by letters A (10) to F (15). A more intuitive approach uses positional weights: each binary digit corresponds to a power of 2 (… 2⁴ = 16, 2³ = 8, 2² = 4, 2¹ = 2, 2⁰ = 1).
数制转换是常考内容。将十进制整数转换为二进制,需反复除以2并记录余数,从下往上读取。转换为十六进制则除以16,余数大于9时用字母A (10)到F (15)表示。更直观的方法是使用位权法:每个二进制位对应2的幂(…… 2⁴ = 16, 2³ = 8, 2² = 4, 2¹ = 2, 2⁰ = 1)。
For example, converting decimal 25 to binary: the highest power of 2 not exceeding 25 is 16 (2⁴). Subtract to leave 9; next is 8 (2³) leaves 1; then 1 (2⁰) uses zero for 2² and 2¹. Thus 25₁₀ = 11001₂. In hexadecimal, 25₁₀ = 19₁₆ because 1×16 + 9×1 = 25. Practising with values between 0 and 255 builds confidence for examination questions.
例如,将十进制数25转换为二进制:不超过25的最大2的幂是16 (2⁴);减去后剩余9;下一个是8 (2³),剩下1;再是1 (2⁰),而2²和2¹位为零。因此25₁₀ = 11001₂。转换为十六进制时,25₁₀ = 19₁₆,因为1×16 + 9×1 = 25。反复练习0到255之间的转换能帮助你从容应对考试题目。
| Decimal | Binary | Hexadecimal |
| 25 | 11001 | 19 |
| 175 | 10101111 | AF |
| 63 | 111111 | 3F |
2. Binary Addition and Overflow | 二进制加法与溢出
Binary addition follows simple rules: 0+0=0, 0+1=1, 1+0=1, and 1+1=0 with a carry of 1 to the next column. When two 8‑bit signed numbers are added and the result exceeds the representable range (−128 to +127 in two’s complement), an overflow occurs. The overflow flag is set when the carry into the most significant bit (MSB) differs from the carry out of the MSB.
二进制加法遵循简单规则:0+0=0,0+1=1,1+0=1,而1+1=0并向高一位进位1。当两个8位有符号数相加,结果超出可表示范围(二进制补码形式下为−128到+127)时,就会发生溢出。若最高有效位(MSB)的进位输入与进位输出不同,溢出标志即被置位。
Worked example: Add 01101011 (107) and 01011010 (90) in 8‑bit two’s complement. The sum is 11000101, but the MSB is now 1, indicating a negative number in two’s complement, while both operands were positive. This signals an overflow. Recognising such conditions is a typical examination item where you must state whether overflow occurred and justify your answer.
计算示例:在8位二进制补码下计算 01101011 (107) 与 01011010 (90) 之和。结果为11000101,但现在MSB为1,在补码中表示负数,而两个操作数均为正数。这便标志着溢出。识别此类情况是典型考题,你需要判断是否发生溢出并给出理由。
3. Logic Gates and Truth Table Calculations | 逻辑门与真值表计算
Logic gates form the building blocks of digital circuits. You must be able to determine the output of combinations of AND, OR, NOT, NAND, NOR and XOR gates for given inputs. A truth table systematically lists all possible input combinations and the resulting outputs. For compound expressions such as (A AND B) OR (NOT C), intermediate columns help track the calculation step by step.
逻辑门是数字电路的构建模块。你必须能针对给定输入,确定与门、或门、非门、与非门、或非门和异或门组合的输出。真值表系统地列出所有可能的输入组合及其对应输出。对于像 (A AND B) OR (NOT C) 这样的复合表达式,借助中间列可逐步跟踪计算过程。
For example, when A=1, B=0, C=1: A AND B = 0, NOT C = 0, so the OR operation yields 0. A full truth table demonstrates how the output changes with each input permutation. Practise drawing such tables quickly and accurately; marks are often awarded for correct column layout and the final output column.
例如,当 A=1、B=0、C=1 时:A AND B = 0,NOT C = 0,因此 OR 运算结果为0。完整的真值表展示了输出如何随各输入排列而变化。请练习快速准确绘制这类表格;评分时常对正确的列布局和最终输出列给予分数。
4. Simplifying Boolean Expressions | 布尔代数化简
Boolean simplification reduces logic circuits to their most efficient forms. Key laws include the identity law (A+0 = A), annulment law (A·0 = 0), idempotent law (A+A = A), absorption law (A + A·B = A) and De Morgan’s theorems ((A·B)’ = A’ + B’ and (A+B)’ = A’·B’). In exam questions, you may be asked to simplify an expression algebraically or prove that two expressions are equivalent.
布尔代数化简可将逻辑电路归约为最简形式。关键定律包括同一律 (A+0 = A)、零律 (A·0 = 0)、重叠律 (A+A = A)、吸收律 (A + A·B = A) 以及德摩根定理 ((A·B)’ = A’ + B’ 和 (A+B)’ = A’·B’)。考试可能要求你对表达式进行代数化简,或证明两个表达式等价。
Consider the expression X = A·B + A·B’. Factor out A: X = A·(B + B’). Since B + B’ = 1, X simplifies to A. Another frequent task is converting a truth table into a simplified Boolean equation using sum-of-products or Karnaugh maps. Clear, logical steps earn full credit.
以表达式 X = A·B + A·B’ 为例。提取公因子 A:X = A·(B + B’)。因为 B + B’ = 1,所以 X 简化为 A。另一常见任务是将真值表转换为最简布尔方程,可以采用积之和式或卡诺图。清晰、逻辑严密的步骤能赢得满分。
5. Image and Sound File Size Calculations | 图像与声音文件大小计算
Calculating file sizes for images and sound is a staple of the exam. The formula for an uncompressed bitmap image is:
File size (bytes) = width (pixels) × height (pixels) × colour depth (bits) ÷ 8
For example, a 1024×768 image with 24‑bit colour requires 1024 × 768 × 24 ÷ 8 = 2,359,296 bytes, roughly 2.25 MiB. Remember that 1 KiB = 1024 bytes, 1 MiB = 1024² bytes, but in some exam contexts 1 KB = 1000 bytes; always check the paper’s convention.
图像与声音文件大小的计算是考试必考内容。未压缩位图图像的计算公式为:
文件大小(字节)= 宽度(像素)× 高度(像素)× 色彩深度(位)÷ 8
例如,一幅 1024×768 像素、24位色彩的图像需要 1024 × 768 × 24 ÷ 8 = 2,359,296 字节,约 2.25 MB。须注意 1 KiB = 1024 字节,1 MiB = 1024² 字节,但某些考试场景中 1 KB = 1000 字节;务必确认试卷采用的单位约定。
For audio, the formula is:
File size (bytes) = sample rate (Hz) × bit depth × number of channels × duration (seconds)
A 30‑second stereo recording at 44.1 kHz and 16‑bit depth uses 44100 × 16 × 2 × 30 = 42,336,000 bits ≈ 5.04 MB. You may also need to calculate streaming bandwidth or compression ratios from such values.
对于音频,公式为:
文件大小(字节)= 采样率(Hz)× 位深度 × 声道数 × 时长(秒)
一段采样率44.1 kHz、16位深度、30秒的立体声录音需 44100 × 16 × 2 × 30 = 42,336,000 比特 ≈ 5.04 MB。有时还需根据这些值计算流媒体带宽或压缩比。
6. Data Compression Ratios | 数据压缩比率
Compression ratio is a measure of how much a file size is reduced. It is calculated as:
Compression ratio = original size / compressed size
A ratio of 4:1 means the compressed file is one‑quarter of the original. Alternatively, you might be asked for the space saving percentage: ((original − compressed) / original) × 100%. In exam problems, you may be given the compressed size and the ratio and need to reconstruct the original size, or evaluate the effectiveness of lossy versus lossless compression on text, images or audio.
压缩比率衡量文件大小的缩减程度。其计算公式为:
压缩比 = 原始大小 ÷ 压缩后大小
4:1 的压缩比意味着压缩文件是原始文件的四分之一。有时也会要求计算节省空间的百分比:((原始大小 – 压缩后大小) ÷ 原始大小) × 100%。考试可能给出压缩后大小和比例,让你反推原始大小,或评估有损压缩与无损压缩对文本、图像或音频的效果。
7. Subnet Mask and IP Addressing Calculations | 子网掩码与IP地址计算
Networking calculation questions focus on determining the network address, broadcast address, and the number of usable hosts from a given IP address and subnet mask or CIDR notation. For a host with IP 192.168.10.15/24, the subnet mask is 255.255.255.0. Performing a bitwise AND between the IP and the mask yields the network address 192.168.10.0. The number of hosts is 2^(32 − prefix) − 2.
网络计算题的重点是根据给定的IP地址和子网掩码或CIDR表示法,确定网络地址、广播地址和可用主机数。对于IP地址 192.168.10.15/24,子网掩码为 255.255.255.0。将IP与掩码进行按位与运算,得到网络地址 192.168.10.0。主机数量为 2^(32 − 前缀) − 2。
For a /27 network (mask 255.255.255.224), the host bits are 5, giving 2⁵ − 2 = 30 usable addresses. You may also need to divide a larger network into subnets of a specified size, calculating the appropriate prefix length. Practising binary representation of IP octets is essential for speed and accuracy.
对于 /27 网络(掩码 255.255.255.224),主机位为5,可提供 2⁵ − 2 = 30 个可用地址。有时还需将一个较大网络划分为指定大小的子网,并计算出合适的前缀长度。练习IP各字节的二进制表示对提升速度和准确性至关重要。
8. Time and Space Complexity of Algorithms | 算法的时间与空间复杂度计算
Algorithm analysis questions require you to determine the time or space complexity of a given pseudocode snippet. Common complexities include O(1) constant, O(log n) logarithmic, O(n) linear, O(n log n) linearithmic, O(n²) quadratic and O(2ⁿ) exponential. A linear search through an unsorted array has a worst‑case time of O(n); binary search on a sorted array runs in O(log n).
算法分析题要求你确定给定伪代码片段的时间或空间复杂度。常见复杂度包括 O(1) 常数级、O(log n) 对数级、O(n) 线性级、O(n log n) 线性对数级、O(n²) 平方级和 O(2ⁿ) 指数级。对未排序数组的线性搜索最坏情况耗时为 O(n);对已排序数组的二分查找运行在 O(log n)。
When loops are nested, multiply their iterations. A nested loop where each runs n times yields O(n²). If operations are sequential, the dominant term dictates the overall complexity; constants and lower‑order terms are discarded. You may also be asked to count steps or memory cells used as a function of input size n.
当循环嵌套时,将各循环迭代次数相乘。两个各运行 n 次的嵌套循环产生 O(n²) 复杂度。若操作为顺序执行,则主导项决定整体复杂度,常数项和低阶项均被舍弃。考题也可能要求你以输入规模 n 的函数形式,统计执行步数或使用的存储单元数。
9. Recursion and Iteration Formula Calculations | 递归与迭代公式计算
Recursive algorithms define a function in terms of itself with a base case. The Fibonacci sequence is a classic example: Fib(0)=0, Fib(1)=1, Fib(n)=Fib(n−1)+Fib(n−2). Tracing a recursive call by hand requires carefully unwinding the stack, recording each function call’s return value. For n=5, Fib(5) evaluates to 5 through a series of subm problems.
递归算法通过自身定义函数并设立基准情形。斐波那契数列是一个经典例子:Fib(0)=0, Fib(1)=1, Fib(n)=Fib(n−1)+Fib(n−2)。手动追踪递归调用需要仔细展开栈,记录每次函数调用的返回值。对于 n=5,Fib(5) 通过一系列子问题得出结果 5。
Converting recursion to iteration often improves efficiency. The iterative Fibonacci calculates values in a loop, storing only the two previous numbers, achieving O(n) time and O(1) space. You may be asked to complete a trace table for a recursive algorithm or to derive a recurrence relation that describes its time complexity.
将递归转换为迭代常能提高效率。迭代式斐波那契算法在循环中计算数值,仅存储前两个数,达到 O(n) 时间和 O(1) 空间。考试可能要求补全递归算法的追踪表,或推导描述其时间复杂度的递推关系式。
10. Checksums and Hamming Distance | 校验码与汉明距离计算
Error detection and correction calculations involve checksums, parity bits and Hamming codes. A simple checksum sums all data bytes, discarding carries beyond 8 bits, and appends the result. The receiver recomputes the sum; a mismatch indicates an error. Parity bits can be even or odd; the number of 1s including the parity bit must be even (for even parity).
差错检测与纠正的计算题涉及校验和、奇偶校验位和汉明码。简单的校验和将全部数据字节相加,丢弃超出8位的进位,并将结果附加在数据后。接收方重新计算总和;不一致则表明存在错误。奇偶校验位可为偶校验或奇校验;包括校验位在内的1的个数必须为偶数(偶校验)。
Hamming distance measures the number of differing bits between two binary strings. To detect d errors, the minimum Hamming distance must be d+1; to correct d errors, distance must be 2d+1. For example, codewords 1100 and 1010 have a Hamming distance of 2, so they can detect single‑bit errors but not correct them. These concepts often appear in structured questions on transmission reliability.
汉明距离衡量两个二进制串之间不同位的个数。要检测 d 个错误,最小汉明距离必须为 d+1;要纠正 d 个错误,距离须为 2d+1。例如,码字 1100 和 1010 的汉明距离为 2,因此它们能检测单个位错误但无法纠正。这些概念常在关于传输可靠性的结构化问题中出现。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导