📚 IB and AQA Computer Science: Calculation Practice Drills | IB与AQA计算机科学:计算题专项训练
Mastering calculation-based questions is essential for success in both IB Computer Science and AQA A-level Computer Science. These exercises test your ability to apply numerical methods across a range of topics, from data representation to algorithm analysis. This guide provides focused drills to sharpen your skills.
掌握计算题对于 IB 计算机科学和 AQA A-level 计算机科学的成功至关重要。这些练习测试你在数据表示、算法分析等各主题中应用数值方法的能力。本指南提供专项训练,帮你强化技能。
1. Number System Conversions | 数字系统转换
Both IB and AQA exam boards expect you to convert fluently between denary, binary and hexadecimal. The core method for denary-to-binary is repeated division by 2, while hex-to-binary uses groups of four bits.
IB 和 AQA 考试都要求你熟练进行十进制、二进制和十六进制之间的转换。十进制转二进制的核心方法是反复除以2,而十六进制转二进制则采用四位一组的方式。
Example: Convert 219 to binary. 219 ÷ 2 = 109 R1, 109 ÷ 2 = 54 R1, 54 ÷ 2 = 27 R0, 27 ÷ 2 = 13 R1, 13 ÷ 2 = 6 R1, 6 ÷ 2 = 3 R0, 3 ÷ 2 = 1 R1, 1 ÷ 2 = 0 R1. Reading remainders bottom-up gives 11011011₂.
示例:将219转为二进制。219 ÷ 2 = 109 余1,109 ÷ 2 = 54 余1,54 ÷ 2 = 27 余0,27 ÷ 2 = 13 余1,13 ÷ 2 = 6 余1,6 ÷ 2 = 3 余0,3 ÷ 2 = 1 余1,1 ÷ 2 = 0 余1。余数自下而上读得 11011011₂。
For hex to binary, treat each hex digit separately using a 4-bit nibble. 0x5F becomes 0101 1111, which is 01011111₂. Denary to hex is best done by converting to binary first or dividing repeatedly by 16 and using digits 0–F.
十六进制转二进制时,将每位十六进制数用4位二进制替换。0x5F 变为 0101 1111,即 01011111₂。十进制转十六进制最好先转为二进制,或反复除以16,使用数字0–F。
2. Binary Arithmetic & Overflow | 二进制算术与溢出
In two’s complement representation, addition and subtraction follow the same hardware rules. To subtract B from A, take the two’s complement of B (invert all bits and add 1) and add it to A.
在补码表示中,加法和减法遵循相同的硬件规则。计算 A – B 时,求B的补码(所有位取反后加1),再与A相加。
Example: Using 8-bit two’s complement, compute 65 – 30. 65 is 01000001₂, 30 is 00011110₂. Two’s complement of 30: invert → 11100001, add 1 → 11100010. Now 01000001 + 11100010 = 1 00100011₂. The carry-out beyond 8 bits is ignored; the result is 00100011₂ = 35.
示例:使用8位补码计算65 – 30。65为01000001₂,30为00011110₂。30的补码:取反→11100001,加1→11100010。相加01000001 + 11100010 = 1 00100011₂。超出8位的进位忽略,结果为00100011₂ = 35。
Overflow occurs when the carry into the sign bit differs from the carry out of the sign bit. For instance, 100 + 50 in 8-bit signed (01100100 + 00110010) gives 10010110₂, which is negative – a clear overflow for positive operands.
当符号位的进位和出位不同时发生溢出。例如,8位有符号数100 + 50(01100100 + 00110010)得10010110₂,为负数,正数相加出现溢出。
3. Floating-Point Representation | 浮点数表示
IB and AQA use a simplified floating-point model with a mantissa and exponent, both in two’s complement. A typical format might use 8-bit mantissa, 4-bit exponent. The mantissa is a normalised fraction starting with 0.1 for positive numbers.
IB 和 AQA 使用简化的浮点模型,尾数和阶码均采用补码。典型格式使用8位尾数、4位阶码。尾数是规格化后的纯小数,正数以0.1开头。
Convert 5.75 to floating-point with 8-bit mantissa, 4-bit exponent. 5.75 = 101.11₂ = 0.10111 × 2³. Exponent 3 in 4-bit two’s complement is 0011. Mantissa normalised: 0.1011100 (fill to 7 fraction bits). Sign bit is 0. So representation: sign 0, mantissa 01011100? Wait: 8-bit mantissa is sign + 7-bit fraction. 0.1011100 becomes 01011100. The full 12-bit word: 01011100 0011.
将5.75转为8位尾数、4位阶码的浮点数。5.75 = 101.11₂ = 0.10111 × 2³。阶码3的4位补码是0011。尾数规格化为0.1011100(填满7位小数)。符号位0。所以完整12位字:尾数01011100,阶码0011。
To retrieve the value, recompute: mantissa = +0.1011100₂ = (1 × ½) + (0 × ¼) + (1 × ⅛) + (1 × ¹⁄₁₆) + (1 × ¹⁄₃₂) + (0 × ¹⁄₆₄) + (0 × ⅛) = 0.71875. Multiply by 2³: 0.71875 × 8 = 5.75.
还原数值:尾数 = +0.1011100₂ = 0.71875,乘以 2³ 得5.75。
4. Logic Gates & Boolean Simplification | 逻辑门与布尔代数化简
Exam questions often ask you to simplify Boolean expressions using identities such as De Morgan’s laws, distribution and absorption. A simpler expression can reduce the number of gates.
考试常要求你使用德摩根律、分配律、吸收律等恒等式化简布尔表达式。化简后可减少逻辑门数量。
Simplify (A + B) • (A + C). Distribute: A + (B • C). The circuit thus requires one OR and one AND gate instead of two ORs and an AND.
化简 (A + B) • (A + C)。分配得 A + (B • C)。这样只需一个或门加一个与门,而非两个或门和一个与门。
Use a truth table to verify: when A=1, output=1; when A=0, output= B•C. The original expression also behaves identically. Hence the simplification is valid.
用真值表验证:A=1时输出1;A=0时输出为B•C。原表达式行为相同,化简有效。
5. Image & Sound Encoding Sizes | 图像与声音编码大小计算
Image file size (in bytes) = (width in pixels × height in pixels × colour depth in bits) / 8. For a 1024×768 image with 24-bit colour, size = (1024 × 768 × 24) / 8 = 2,359,296 bytes ≈ 2.25 MiB.
图像文件大小(字节)=(宽度像素 × 高度像素 × 颜色深度位)/8。1024×768、24位色的图像,大小 = (1024 × 768 × 24) / 8 = 2,359,296 字节 ≈ 2.25 MiB。
Sound file size = sample rate × bit depth × number of channels × duration (seconds). CD-quality stereo (44.1 kHz, 16-bit) for 1 minute: 44100 × 16 × 2 × 60 = 84,672,000 bits = 10,584,000 bytes ≈ 10.09 MiB.
声音文件大小 = 采样率 × 位深度 × 声道数 × 时长(秒)。CD质量立体声(44.1 kHz, 16位)1分钟:44100 × 16 × 2 × 60 = 84,672,000 位 = 10,584,000 字节 ≈ 10.09 MiB。
6. Subnetting Calculations | 子网划分计算
Given an IP address and a CIDR prefix, calculate the subnet mask, network address, broadcast address and usable host range. For 192.168.1.0/26, the subnet mask is 255.255.255.192. The number of host bits = 32 – 26 = 6, so addresses per subnet = 2⁶ = 64, with 62 usable hosts.
给定IP地址和CIDR前缀,计算子网掩码、网络地址、广播地址和可用主机范围。对于192.168.1.0/26,子网掩码为255.255.255.192。主机位数 = 32 – 26 = 6,每子网地址数 2⁶ = 64,可用主机62个。
| Subnet Number | Network Address | First Host | Last Host | Broadcast |
| 1st | 192.168.1.0 | 192.168.1.1 | 192.168.1.62 | 192.168.1.63 |
| 2nd | 192.168.1.64 | 192.168.1.65 | 192.168.1.126 | 192.168.1.127 |
Quick check: the broadcast address is the last address in the block where all host bits are 1. The network address has all host bits 0.
快速校验:广播地址是块中所有主机位为1的最后一个地址。网络地址所有主机位为0。
7. Scheduling Algorithms Metrics | 调度算法指标计算
CPU scheduling problems ask for average waiting time and average turnaround time. Suppose processes arrive at time 0 with burst times: P1=8, P2=4, P3=2.
CPU调度问题要求计算平均等待时间和平均周转时间。假设进程在时刻0同时到达,爆发时间为:P1=8, P2=4, P3=2。
| Algorithm | Execution Order | Wait Time P1/P2/P3 | Average Wait |
| FCFS | P1, P2, P3 | 0,8,12 | (0+8+12)/3 = 6.67 |
| SJF | P3, P2, P1 | 6,2,0 | (6+2+0)/3 = 2.67 |
Turnaround time = completion time – arrival time. For FCFS: P1=8, P2=12, P3=14, avg = 11.33. SJF: P3=2, P2=6, P1=14, avg = 7.33. SJF minimises average wait.
周转时间 = 完成时间 – 到达时间。FCFS:P1=8, P2=12, P3=14, 平均11.33。SJF:P3=2, P2=6, P1=14, 平均7.33。SJF最小化平均等待时间。
8. Disk Access Time | 磁盘存取时间
Disk access time = seek time + rotational latency + transfer time. Rotational latency is half the time for one revolution. If the disk spins at 7200 rpm, one revolution time = 60 s / 7200 ≈ 8.33 ms, so average latency ≈ 4.17 ms.
磁盘访问时间 = 寻道时间 + 旋转延迟 + 传输时间。旋转延迟为旋转一圈所需时间的一半。若磁盘转速7200 rpm,每圈时间 = 60秒 / 7200 ≈ 8.33 ms,平均延迟 ≈ 4.17 ms。
Add a typical average seek of 5 ms and a very small transfer time of 0.1 ms, total access time ≈ 9.27 ms. Exam questions usually ask you to compute the total for a given seek and rpm.
加上典型平均寻道5 ms和极小的传输时间0.1 ms,总访问时间 ≈ 9.27 ms。考试常要求你根据给定的寻道时间和转速计算总时间。
9. Algorithm Complexity (Big-O) | 算法复杂度(大O)
Determine the time complexity of a nested loop. For i from 0 to n-1, for j from 0 to i-1: the inner statement runs 0 + 1 + 2 + … + (n-1) = n(n-1)/2 times. This is O(n²).
判断嵌套循环的时间复杂度。i 从0到n-1,j 从0到i-1:内部语句执行 0+1+2+…+(n-1) = n(n-1)/2 次,复杂度 O(n²)。
Binary search repeatedly halves the search space, leading to at most ⌊log₂n⌋ + 1 comparisons, thus O(log n). Linear search inspects each element once: O(n).
二分查找每次将搜索空间减半,最多 ⌊log₂n⌋ + 1 次比较,故 O(log n)。线性搜索依次检查每个元素,O(n)。
10. Recursion & Stack Depth | 递归与栈深度
Recursive functions consume stack space. For factorial(n), the recursion depth is n. factorial(6) calls itself 6 times before unwinding, using 6 stack frames. Stack overflow occurs if depth exceeds system limits.
递归函数消耗栈空间。对于 factorial(n),递归深度为 n。factorial(6) 在返回前会调用自身6次,占用6个栈帧。深度超过系统限制会导致栈溢出。
Consider Fibonacci: fib(n) = fib(n-1) + fib(n-2). The call tree size is exponential, around 2ⁿ nodes, giving O(2ⁿ) time complexity but a maximum stack depth of only n (since the recursion is depth-first).
斐波那契:fib(n) = fib(n-1) + fib(n-2)。调用树大小呈指数,约 2ⁿ 个节点,时间复杂度 O(2ⁿ),但最大栈深度仅为 n(因为是深度优先递归)。
11. Assembly Addressing Calculations | 汇编寻址计算
In low-level code, the effective address is computed from base, index and displacement. For a MOV instruction using base-index with displacement: MOV AX, [BX+SI+10H]. If BX = 1000H and SI = 0200H, effective address = 1000H + 0200H + 10H = 1210H.
底层代码中,有效地址由基址、变址和位移计算得出。对于基址变址加位移的寻址:MOV AX, [BX+SI+10H]。若 BX = 1000H,SI = 0200H,有效地址 = 1000H + 0200H + 10H = 1210H。
Another common calculation is the offset for a conditional jump. JMP SHORT label: the offset is an 8-bit signed relative address from the next instruction. If the label is 6 bytes ahead and the current IP after reading the instruction is 0100H, the encoded offset is +6, i.e., 06H.
另一种常见计算是条件跳转的偏移量。JMP SHORT label:偏移量是相对于下一条指令的8位有符号地址。如果标签在本指令之后的6字节处,读取指令后当前IP为0100H,编码偏移量为+6,即06H。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导