IB and OCR Computer Science: Calculation Practice Workbook | IB 与 OCR 计算机科学:计算题专项训练

📚 IB and OCR Computer Science: Calculation Practice Workbook | IB 与 OCR 计算机科学:计算题专项训练

Calculation-based problems are a core component of both IB and OCR Computer Science examinations, appearing in topics ranging from data representation to networking and algorithm analysis. A systematic approach, combined with unit-awareness and logico-mathematical fluency, is essential for building speed and accuracy. This workbook consolidates the most common calculation question types across both syllabi and provides worked examples and strategies.

计算类题目是 IB 与 OCR 计算机科学考试的核心组成部分,广泛出现在数据表示、网络、算法分析等主题中。系统性的解题方法、单位意识以及逻辑数学的流畅度对于提升速度和准确率至关重要。本文汇总了两种课程体系中最常见的计算题型,并提供详尽的示例和策略。

1. Number System Conversions | 数字系统转换

You must be able to convert between binary, decimal, and hexadecimal, including fractional values. The key is to remember place values and to use repeated division or multiplication.

必须掌握二进制、十进制和十六进制之间的相互转换,包括小数值。关键在于牢记位权并使用重复除法或乘法。

Decimal to Binary (integer): Divide the decimal number by 2 repeatedly, noting the remainders. The binary result is the remainders read from bottom to top. For example, convert 15610 to binary. 156 ÷ 2 = 78 R0, 78 ÷ 2 = 39 R0, 39 ÷ 2 = 19 R1, 19 ÷ 2 = 9 R1, 9 ÷ 2 = 4 R1, 4 ÷ 2 = 2 R0, 2 ÷ 2 = 1 R0, 1 ÷ 2 = 0 R1. Reading remainders upwards gives 10011100₂.

十进制转二进制(整数): 将十进制数反复除以 2,记录余数。从下往上读取余数即为二进制结果。例如,将 15610 转为二进制:156 ÷ 2 = 78 余0,78 ÷ 2 = 39 余0,39 ÷ 2 = 19 余1,19 ÷ 2 = 9 余1,9 ÷ 2 = 4 余1,4 ÷ 2 = 2 余0,2 ÷ 2 = 1 余0,1 ÷ 2 = 0 余1。向上读取余数得到 10011100₂。

Hexadecimal to Binary: Each hex digit expands to a 4-bit binary nibble. For instance, 3F16 becomes 0011 1111₂ (often written without leading zeros as 111111₂).

十六进制转二进制: 每个十六进制数字展开为 4 位二进制半字节。例如,3F16 变为 0011 1111₂(常去掉前导零写作 111111₂)。

Fractional Conversion: For decimal fractions to binary, multiply the fraction by 2, take the integer part as the next bit, and repeat with the fractional part. Convert 0.62510: 0.625×2=1.25 → 1, 0.25×2=0.5 → 0, 0.5×2=1.0 → 1. So 0.62510 = 0.101₂. Straight to exam-style conversion questions.

小数转换: 十进制小数转二进制时,将小数部分乘以 2,取整数部分作为下一位二进制位,并用剩下的小数部分重复操作。转换 0.62510:0.625×2=1.25 → 1,0.25×2=0.5 → 0,0.5×2=1.0 → 1。因此 0.62510 = 0.101₂。直接应对考试中的转换题。


2. Memory and Storage Calculations | 内存与存储计算

Questions often ask for addressable memory given an address bus width or to calculate the storage capacity of a device. The fundamental formula: addressable locations = 2n, where n is the number of address lines. Then multiply by word size if needed.

考题常要求根据地址总线宽度计算可寻址内存,或计算某设备的存储容量。基本公式:可寻址单元数 = 2ⁿ,其中 n 是地址线数量。如需,再乘以字长。

If a CPU has a 24-bit address bus and each memory location stores 1 byte, the total addressable memory is 2²⁴ bytes = 16 777 216 bytes = 16 MiB. Use the binary prefixes: 1 KiB = 2¹⁰ B, 1 MiB = 2²⁰ B.

若 CPU 地址总线为 24 位且每个存储单元存放 1 字节,则可寻址内存为 2²⁴ 字节 = 16 777 216 字节 = 16 MiB。务必使用二进制前缀:1 KiB = 2¹⁰ B,1 MiB = 2²⁰ B。

Hard disk capacity: number of platters × tracks per surface × sectors per track × bytes per sector. A disk with 4 platters (8 surfaces), 1000 tracks, 200 sectors/track, and 512 bytes/sector gives: 8 × 1000 × 200 × 512 = 819 200 000 bytes ≈ 781 MiB. Always show unit conversions carefully.

硬盘容量:盘片数 × 每面磁道数 × 每道扇区数 × 每扇区字节数。一片有 4 个盘片(8 个面)、1000 磁道、200 扇区/道、512 字节/扇区的硬盘容量为:8×1000×200×512 = 819 200 000 字节 ≈ 781 MiB。务必仔细展示单位换算。


3. Image and Sound File Size Calculations | 图像与声音文件大小计算

Image file size = horizontal pixels × vertical pixels × colour depth (bits). For a true-colour image of 1920×1080 with 24-bit colour, uncompressed size = 1920 × 1080 × 24 = 49 766 400 bits = 6 220 800 B ≈ 5.93 MiB. Beware of converting bits to bytes (divide by 8).

图像文件大小 = 水平像素 × 垂直像素 × 色深(位)。一张 1920×1080、24 位真彩色的图像,未压缩大小为 1920×1080×24 = 49 766 400 比特 = 6 220 800 字节 ≈ 5.93 MiB。注意比特到字节的转换(除以 8)。

Sound file size = sample rate × bit depth × number of channels × duration. For 1 minute of stereo audio at 44.1 kHz and 16-bit: 44 100 × 16 × 2 × 60 = 84 672 000 bits = 10 584 000 B ≈ 10.1 MiB. The duration must be in seconds.

声音文件大小 = 采样频率 × 位深度 × 声道数 × 时长。1 分钟、44.1 kHz、16 位立体声音频的大小为:44 100×16×2×60 = 84 672 000 比特 = 10 584 000 字节 ≈ 10.1 MiB。时长必须使用秒。

Some exam boards require expressing results in kibibytes or mebibytes. Always apply 1024-based division.

部分考试局要求结果以 kibibyte 或 mebibyte 表示,始终使用 1024 进制进行除法。


4. Data Transmission Time Calculations | 数据传输时间计算

The universal formula: time (s) = data size (bits) / bandwidth (bits per second). Rearrange as needed. Convert all quantities to bits before dividing.

通用公式:时间(秒)= 数据量(比特)/ 带宽(比特每秒)。根据需要重新排列。在相除之前将所有量转换为比特。

A 5 MiB file over a 100 Mbps connection: data size = 5 × 2²⁰ × 8 = 41 943 040 bits. Time = 41 943 040 / (100 × 10⁶) ≈ 0.419 s. Beware that network bandwidth is often in decimal megabits (1 Mbps = 10⁶ bps), while file size uses binary MiB; careful unit handling is critical.

一个 5 MiB 的文件通过 100 Mbps 连接传输:数据量 = 5×2²⁰×8 = 41 943 040 比特。时间 = 41 943 040 / (100×10⁶) ≈ 0.419 秒。注意网络带宽常用十进制的兆比特(1 Mbps = 10⁶ bps),而文件大小用二进制的 MiB;谨慎处理单位至关重要。

For half-duplex or protocols with overhead, multiply the raw data size by an overhead factor (e.g., 1.2 for 20% overhead). IB and OCR may ask for the effect of protocol headers.

对于半双工或有开销的协议,需将原始数据量乘以开销因子(例如 20% 开销则乘 1.2)。IB 与 OCR 可能会要求考虑协议头部的影响。


5. Logic Gates and Boolean Algebra Calculations | 逻辑门与布尔代数计算

These questions involve expression simplification using Boolean laws or truth tables, or calculating the number of gates. For example, simplify A·(A+B). Using absorption: A·(A+B) = A.

此类题目涉及利用布尔定律或真值表化简表达式,或计算门电路数量。例如,化简 A·(A+B),根据吸收律:A·(A+B) = A。

Draw the truth table for a given expression such as (A∧B)∨¬C, then count the rows where output is 1. You might be asked to convert a logic circuit into an expression and then simplify.

为给定表达式绘制真值表,如 (A∧B)∨¬C,然后统计输出为 1 的行数。可能会要求将逻辑电路转换为表达式并化简。

Gate counts: after simplification, the circuit requires fewer gates. A full-adder constructed from NAND gates only uses 9 NAND gates. You may need to calculate the number of standard gates needed after simplifying a Boolean expression. Always show algebraic steps.

门电路数量:化简后电路所需门数减少。仅用与非门构建的全加器需要 9 个与非门。可能需要计算化简布尔表达式后所需的标准门数量。始终展示代数步骤。


6. Checksum and Error Detection | 校验和与错误检测

Calculate a simple longitudinal parity check or an Internet checksum. For a byte-level checksum, sum the data bytes, keep the lower byte, and take the two’s complement. Example: data bytes 0x45, 0x3A. Sum = 0x7F. Checksum = two’s complement of 0x7F → 0x81. The receiver adds all bytes including checksum and expects zero (in one’s complement schemes, all ones).

计算简单的纵向奇偶校验或互联网校验和。对于字节级校验和,将数据字节相加,保留低字节,并取其二进制补码。示例:数据字节 0x45、0x3A。和 = 0x7F。校验和 = 0x7F 的补码 → 0x81。接收方将所有字节(包括校验和)相加,在反码方案中期望得到全 1。

CRC calculations: given a generator polynomial, perform binary long division to find the remainder. The message polynomial multiplied by xⁿ (where n is degree of generator) is divided by the generator polynomial; the remainder is the CRC code. Provide step-by-step binary division.

CRC 计算:给定生成多项式,执行二进制长除法以求得余数。消息多项式乘以 xⁿ(n 为生成多项式次数)后除以生成多项式,余数即为 CRC 码。需逐步展示二进制除法。

Hamming distance and error detection/correction capabilities: to detect up to d errors, distance ≥ d+1; to correct c errors, distance ≥ 2c+1. These are calculation-based MCQs.

汉明距离与检错纠错能力:要检测最多 d 个错误,距离 ≥ d+1;要纠正 c 个错误,距离 ≥ 2c+1。这些常以计算型选择题出现。


7. Compression Ratio Calculations | 压缩率计算

Compression ratio = uncompressed size / compressed size. A 800 KB image compressed to 200 KB gives a ratio of 4:1. The space saving is (uncompressed − compressed) / uncompressed × 100%.

压缩比 = 未压缩大小 / 压缩后大小。一张 800 KB 图像压缩至 200 KB,压缩比为 4:1。节省的空间百分比 =(未压缩−压缩)/ 未压缩 × 100%。

Lossy compression may use bit rate calculations for audio. If a 128 kbps stream encodes 3 minutes of audio, file size = 128 × 10³ × 3 × 60 / 8 = 2.88 MB. Compare with CD-quality size (1411 kbps) to demonstrate compression.

有损压缩可能涉及音频的比特率计算。若 128 kbps 码流编码 3 分钟音频,文件大小 = 128×10³×3×60 / 8 = 2.88 MB。与 CD 音质的 1411 kbps 大小对比,可展示压缩效果。

Be ready to calculate the compressed size from a given ratio or vice versa. Use consistent decimal/binary prefixes as specified on the paper.

需熟练掌握根据给定压缩比计算压缩后的大小,或反向计算。使用试卷指定的十进制/二进制前缀保持一致。


8. IP Address and Subnet Mask Calculations | IP 地址与子网掩码计算

Given an IP address and subnet mask (e.g., 192.168.1.100/26), calculate the network address by bitwise AND. The /26 means the first 26 bits are the network portion. Convert to binary: 192.168.1.100 → 11000000.10101000.00000001.01100100. Mask /26 → 11111111.11111111.11111111.11000000. AND yields network 192.168.1.64. The broadcast address is the last address in block: 192.168.1.127. Number of hosts = 2^(32-26) – 2 = 62.

给定 IP 地址与子网掩码(如 192.168.1.100/26),通过按位与运算计算网络地址。 /26 表示前 26 位为网络部分。转换为二进制:192.168.1.100 → 11000000.10101000.00000001.01100100。掩码 /26 → 11111111.11111111.11111111.11000000。与运算得网络地址 192.168.1.64。广播地址为块内最后一个地址:192.168.1.127。主机数 = 2^(32-26) – 2 = 62。

Subnetting design: Given a required number of subnets or hosts per subnet, determine the appropriate prefix length. If you need at least 100 hosts, 2ⁿ – 2 ≥ 100 → n=7 (since 2⁷-2=126), leaving 32-7=25 bits for network part, so /25 mask. For OCR, this appears in network calculations.

子网划分设计:根据所需的子网数或每子网主机数,确定合适的前缀长度。若需要至少 100 台主机,2ⁿ – 2 ≥ 100 → n=7(因 2⁷-2=126),网络部分占 32-7=25 位,即 /25 掩码。在 OCR 考试中,这是常见的网络计算题。


9. Encryption Algorithm Calculations | 加密算法计算

RSA numerical example: choose primes p=3, q=11 (small for exam). n = 33, φ(n)=20. Choose e=3 (coprime with 20). Compute private key d such that e·d mod φ(n) = 1 → 3d mod 20 = 1, d=7. Encrypt message M=4: C = M^e mod n = 4^3 mod 33 = 64 mod 33 = 31. Decrypt: C^d mod n = 31^7 mod 33. Break into (31^3 mod 33 × 31^4 mod 33) etc. Eventually yields 4. You must be comfortable with modular exponentiation tricks.

RSA 数值示例:选取质数 p=3、q=11(考试用小数)。n=33,φ(n)=20。选择 e=3(与 20 互质)。计算私钥 d 使 e·d mod φ(n) = 1 → 3d mod 20 = 1,d=7。加密消息 M=4:密文 C = Mᵉ mod n = 4³ mod 33 = 64 mod 33 = 31。解密:Cᵈ mod n = 31⁷ mod 33。可拆分为 (31³ mod 33 × 31⁴ mod 33) 等。最终得到 4。必须熟练掌握模幂运算技巧。

Diffie-Hellman key exchange: given public values g and p, and private keys a and b, compute shared key. Example: p=23, g=5. Alice a=6: A = 5⁶ mod 23 = 15625 mod 23 = 8. Bob b=15: B = 5¹⁵ mod 23 = … = 19. Shared key = 19⁶ mod 23 = 8¹⁵ mod 23 = 2. Show intermediate mod steps efficiently.

Diffie-Hellman 密钥交换:给定公开值 g 和 p,以及私钥 a 和 b,计算共享密钥。示例:p=23,g=5。Alice a=6:A = 5⁶ mod 23 = 15625 mod 23 = 8。Bob b=15:B = 5¹⁵ mod 23 = … = 19。共享密钥 = 19⁶ mod 23 = 8¹⁵ mod 23 = 2。高效展示中间取模步骤。


10. Algorithm Time Complexity Analysis | 算法时间复杂度计算

Calculate the number of elementary operations as a function of input size n. A simple nested loop: for i=1 to n, for j=1 to i, do something. The number of iterations = n(n+1)/2, leading to O(n²). Explain summation approach.

计算基本操作次数与输入规模 n 的关系。一个简单的嵌套循环:for i=1 to n, for j=1 to i, 执行某操作。迭代次数 = n(n+1)/2,时间复杂度为 O(n²)。解释累加求和方法。

Binary search: worst-case comparisons floor(log₂ n) + 1. For n=32, max comparisons = 6. Derive from the recurrent halving. Provide formula in Big O notation O(log n).

二分查找:最坏情况比较次数为 floor(log₂ n) + 1。对于 n=32,最多比较 6 次。可通过重复折半推导。用大 O 记号表示为 O(log n)。

Recursive algorithms like factorial: recurrence T(n)=T(n-1)+O(1) gives O(n). Merge sort: T(n)=2T(n/2)+O(n) solves to O(n log n). You may need to substitute values and trace for small n in an exam.

递归算法如阶乘:递推式 T(n)=T(n-1)+O(1) 得出 O(n)。归并排序:T(n)=2T(n/2)+O(n) 求解为 O(n log n)。考试中可能需要替换数值并对小的 n 进行跟踪。

Understand how to compare growth rates: O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ) < O(n!). Use these to rank algorithms or predict performance.

理解增长率的比较:O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ) < O(n!)。可据此为算法排序或预测性能。


Published by TutorHao | 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