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

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

Numerical and logical calculations form the backbone of Computer Science assessments in both IB and OCR specifications. From converting number bases to estimating file sizes, algorithm efficiency, and memory addressing, students must apply formulas accurately, pay attention to units, and reason through multi-step problems. This article provides a targeted training set covering the most frequently examined calculation types, with step‑by‑step examples and bilingual explanations to reinforce understanding.

数值与逻辑计算是 IB 和 OCR 计算机科学评估的核心。从数制转换到估算文件大小、算法效率和内存寻址,学生必须准确运用公式、注意单位换算并逐步推理。本文提供一份专项训练,覆盖最常见的计算题型,配有分步示例和中英双语讲解,以加深理解。


1. Number System Conversions | 数制转换

Mastering conversions between binary, decimal, and hexadecimal is essential. For decimal to binary, repeatedly divide by 2 and record remainders; read remainders bottom‑up. For binary to hexadecimal, group bits into nibbles (4‑bit groups) from the right, then map each to its hex digit. When converting hexadecimal to decimal, multiply each hex digit by 16ⁿ, where n is the position (starting at 0 from right).

熟练掌握二进制、十进制和十六进制之间的转换是基础。十进制转二进制时连续除以 2 并记录余数,从下往上读。二进制转十六进制时将位从右向左每 4 位分组,再映射到十六进制数字。十六进制转十进制则将每位乘以 16ⁿ(n 为从右起的位置,从 0 开始)。

Example:

  • Convert 156 (decimal) to binary: 156 ÷ 2 = 78 rem 0; 78 ÷ 2 = 39 rem 0; 39 ÷ 2 = 19 rem 1; 19 ÷ 2 = 9 rem 1; 9 ÷ 2 = 4 rem 1; 4 ÷ 2 = 2 rem 0; 2 ÷ 2 = 1 rem 0; 1 ÷ 2 = 0 rem 1 → reading upwards: 10011100₂
  • Convert 1010 1110₂ to hex: 1010 = A, 1110 = E → AE₁₆
  • Convert 2F₁₆ to decimal: (2 × 16¹) + (15 × 16⁰) = 32 + 15 = 47₁₀
  • 将 156(十进制)转二进制: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₂
  • 1010 1110₂ 转十六进制:1010 = A,1110 = E → AE₁₆
  • 2F₁₆ 转十进制:(2 × 16¹) + (15 × 16⁰) = 32 + 15 = 47₁₀
Decimal Binary (4‑bit) Hex
10 1010 A
15 1111 F

2. Binary Arithmetic | 二进制算术

Binary addition follows simple rules: 0+0=0, 0+1=1, 1+0=1, 1+1=0 carry 1. When the result exceeds the bit width, an overflow occurs. Subtraction is often handled through two’s complement: invert bits and add 1 to form the negative representation, then perform addition.

二进制加法遵循简易规则:0+0=0,0+1=1,1+0=1,1+1=0 进 1。当结果超出位宽时发生溢出。减法通常通过二进制补码处理:按位取反再加 1 得到负数的表示,然后执行加法。

Addition example (8‑bit): 0011 0110 (54) + 0010 1101 (45) = 0101 0011 (83). No overflow because carry into sign bit matches carry out.

加法示例(8 位):0011 0110 (54) + 0010 1101 (45) = 0101 0011 (83)。无溢出,因为符号位进位与进位出相同。

Subtraction via two’s complement: 54 – 45 = 54 + (–45). Represent –45 in 8‑bit two’s complement: 45 = 0010 1101 → invert: 1101 0010 → add 1: 1101 0011. Now add: 0011 0110 + 1101 0011 = 1 0000 1001 (discard extra carry) → 0000 1001 = 9₁₀.

补码减法:54 – 45 = 54 + (–45)。将 –45 表示为 8 位补码:45 = 0010 1101 → 取反:1101 0010 → 加 1:1101 0011。相加:0011 0110 + 1101 0011 = 1 0000 1001(舍弃额外进位)→ 0000 1001 = 9₁₀。

Overflow detection: XOR carry into and out of sign bit

溢出检测:符号位进位与进位出异或


3. Floating Point Representation | 浮点数表示

Real numbers are stored in scientific notation using a sign bit, biased exponent, and mantissa. In IEEE 754 single precision (32‑bit): 1 bit sign, 8 bits exponent (bias +127), 23 bits mantissa (fractional part). Convert a decimal to binary floating point, normalise, encode the exponent with bias, and truncate/pad the mantissa. For example, 10.25₁₀ = 1010.01₂ = 1.01001 × 2³. Sign = 0 (positive), exponent = 3 + 127 = 130 = 10000010₂, mantissa = 01001 followed by zeros to 23 bits.

实数以科学记数法存储,使用符号位、带偏移的指数和尾数。IEEE 754 单精度(32 位)中:1 位符号,8 位指数(偏移 +127),23 位尾数(小数部分)。将十进制转为二进制浮点数,规范化,用偏移量编码指数,并截断/填充尾数。例如,10.25₁₀ = 1010.01₂ = 1.01001 × 2³。符号 = 0(正),指数 = 3 + 127 = 130 = 10000010₂,尾数 = 01001 后补零至 23 位。

To decode: given binary pattern 0 10000010 01001000000000000000000, sign = 0, exponent = 130 – 127 = 3, mantissa = 1.01001₂ → value = +1.01001₂ × 2³ = 1010.01₂ = 10.25. Pay attention to denormalised cases and special values (NaN, infinity).

解码:给定二进制模式 0 10000010 01001000000000000000000,符号 = 0,指数 = 130 – 127 = 3,尾数 = 1.01001₂ → 值 = +1.01001₂ × 2³ = 1010.01₂ = 10.25。注意非规格化情况和特殊值(NaN、无穷大)。

Component Bits Value
Sign 0 Positive
Exponent 10000010₂ 130 – 127 = 3
Mantissa 0100100… (23 bits) 1.01001₂

4. Image File Size Calculation | 图像文件大小计算

The raw size of a bitmap image depends on resolution (width × height) and colour depth (bits per pixel). Formula: Size (bits) = width × height × colour depth. Convert to bytes by dividing by 8, then to larger units (KB, MB) as needed. Note: 1 KB = 1024 B in computing, but sometimes exam boards use 1000—check specification.

位图图像原始大小取决于分辨率(宽度×高度)和色深(每像素位数)。公式:大小(位)= 宽 × 高 × 色深。除以 8 转为字节,再转为更大单位(KB、MB)。注意:计算机中 1 KB = 1024 B,但有时考试局使用 1000——请核对考纲。

Example: A 1920×1080 image with 24‑bit colour. Bits = 1920 × 1080 × 24 = 49,766,400 bits. Bytes = 49,766,400 / 8 = 6,220,800 B ≈ 6.22 MB (if using 1 MB = 1,000,000 B) or ≈ 5.93 MiB.

示例:一幅 1920×1080、24 位色深的图像。位 = 1920 × 1080 × 24 = 49,766,400 位。字节 = 49,766,400 / 8 = 6,220,800 B ≈ 6.22 MB(若 1 MB = 1,000,000 B)或约 5.93 MiB。


5. Sound File Size Calculation | 声音文件大小计算

Uncompressed audio size is determined by sample rate (Hz), bit depth, number of channels, and duration (seconds). Formula: Size (bits) = sample rate × bit depth × channels × duration. Stereo has 2 channels. As with images, convert to bytes and larger units carefully.

未压缩音频大小由采样率(Hz)、位深、声道数和时长(秒)决定。公式:大小(位)= 采样率 × 位深 × 声道数 × 时长。立体声有 2 个声道。与图像一样,仔细转换为字节和更大单位。

Example: 5 seconds of stereo sound at 44.1 kHz, 16‑bit. Bits = 44,100 × 16 × 2 × 5 = 7,056,000 bits = 882,000 bytes ≈ 882 KB or 0.882 MB.

示例:5 秒立体声,44.1 kHz,16 位。位 = 44,100 × 16 × 2 × 5 = 7,056,000 位 = 882,000 字节 ≈ 882 KB 或 0.882 MB。

  • Always check if sample rate is given in kHz; multiply by 1000.
  • 当采样率以 kHz 给出时,务必乘以 1000。

6. Boolean Algebra & Logic Simplification | 布尔代数与逻辑化简

Boolean expressions can be reduced using algebraic laws (identity, complement, distributive, etc.) or Karnaugh maps (K‑maps). The goal is to minimise the number of logic gates. For instance, simplify F = A·B + A·B’. Apply the distributive law: A·(B + B’) = A·1 = A. This reduces two AND gates and one OR gate to a single wire, lowering cost.

布尔表达式可通过代数定律(同一律、互补律、分配律等)或卡诺图化简。目标是减少逻辑门数量。例如,化简 F = A·B + A·B’。使用分配律:A·(B + B’) = A·1 = A。这将两个与门和一个或门简化为一条连线,降低成本。

K‑map example: F(A,B,C) = Σ(1,2,3,6). Plot minterms in a 2×4 map; group adjacent 1s. Result: F = A’·C + B·C’ + A·B? (simplify carefully). Ensure you practise both algebraic and graphical methods.

卡诺图示例:F(A,B,C) = Σ(1,2,3,6)。在 2×4 方格中填入最小项;圈出相邻的 1。最终 F = A’·C + B·C’(具体化简后验证)。确保你同时练习代数法和图形法。

F = A’B’C + A’BC + AB’C’ + AB’C → after grouping: F = A’C + AB’

F = A’B’C + A’BC + AB’C’ + AB’C → 分组后:F = A’C + AB’


7. Logic Gate Cost Calculation | 逻辑门成本计算

Exam questions often ask you to determine the number and type of gates required for a given Boolean expression, or to compare implementations. Each AND, OR, NOT, NAND, etc., may be assigned a cost (e.g., transistor count). For example, implementing A XOR B using basic gates: (A·B’) + (A’·B) requires two NOTs, two ANDs, and one OR, total 5 gates. A NAND‑only implementation might use fewer chips.

考试中常要求计算给定布尔表达式所需的门数量和类型,或比较不同实现成本。每个与、或、非、与非门等可能被赋予成本(如晶体管数)。例如,用基本门实现 A XOR B:(A·B’) + (A’·B) 需要两个非门、两个与门和一个或门,共 5 个门。仅用与非门实现可能使用更少的芯片。

Gate type Typical transistor count (example)
NOT 2
2‑input NAND 4
2‑input AND (from NAND+NOT) 6

8. Data Transmission Time | 数据传输时间

Transmission time (seconds) = amount of data (bits) / bandwidth (bits per second). Always match units: if file size is in MB, convert to bits first (×8 × 10⁶ if using SI units). Network speeds are often in Mbps (10⁶ bits per second). Higher‑level considerations include protocol overhead, but base calculations assume ideal throughput.

传输时间(秒)= 数据量(位)/ 带宽(位/秒)。务必统一单位:如果文件大小以 MB 为单位,先转为位(若用 SI 单位,则 ×8 × 10⁶)。网络速度常以 Mbps(10⁶ 位/秒)表示。高层考虑包括协议开销,但基础计算假设理想吞吐量。

Example: Transfer 50 MB file over a 100 Mbps connection. Data bits = 50 × 8 × 10⁶ = 400 × 10⁶ bits. Time = 400 × 10⁶ / 100 × 10⁶ = 4 seconds. If using binary megabytes (1 MiB = 2²⁰ B): 50 × 2²⁰ × 8 ≈ 419,430,400 bits, time ≈ 4.19 s.

示例:通过 100 Mbps 连接传输 50 MB 文件。数据位 = 50 × 8 × 10⁶ = 400 × 10⁶ 位。时间 = 400 × 10⁶ / 100 × 10⁶ = 4 秒。若使用二进制兆字节(1 MiB = 2²⁰ B):50 × 2²⁰ × 8 ≈ 419,430,400 位,时间约 4.19 秒。


9. Memory Addressing | 内存寻址

The number of uniquely addressable memory locations depends on the address bus width (n bits). Number of locations = 2ⁿ. If each location stores 1 byte (data bus width = 8 bits), then total addressable memory = 2ⁿ bytes. For example, a 16‑bit address bus can address 2¹⁶ = 65,536 bytes = 64 KiB. A 32‑bit address bus offers 4 GiB (2³² B).

可唯一寻址的内存单元数量取决于地址总线宽度(n 位)。单元数 = 2ⁿ。若每个单元存储 1 字节(数据总线宽 8 位),则可寻址内存总量 = 2ⁿ 字节。例如,16 位地址总线可寻址 2¹⁶ = 65,536 字节 = 64 KiB。32 位地址总线提供 4 GiB(2³² B)。

Some systems use word‑addressable memory. Calculate total capacity by multiplying number of locations by word size. Word size is usually a multiple of bytes.

某些系统使用字寻址内存。总容量 = 单元数 × 字长。字长通常是字节的倍数。

  • 16‑bit address bus, 16‑bit word: 2¹⁶ × 2 bytes = 131,072 B = 128 KiB.
  • 16 位地址总线,16 位字长:2¹⁶ × 2 字节 = 131,072 B = 128 KiB。

10. Algorithm Complexity & Steps Count | 算法复杂度与步骤计数

Time complexity is expressed using Big O notation, but exams may ask for the number of operations for a given input size. For a simple nested loop: for i=1 to n: for j=1 to n: print(i,j) the inner statement executes n × n = n² times, so O(n²). When loops are not full, count carefully: for i=1 to n: for j=i to n: ... yields n + (n‑1) + … + 1 = n(n+1)/2, still O(n²).

时间复杂度用大 O 表示法表达,但考试可能要求针对给定输入规模计算操作次数。对于简单嵌套循环:for i=1 to n: for j=1 to n: print(i,j) 内部语句执行 n × n = n² 次,故为 O(n²)。当循环不完整时需仔细计数:for i=1 to n: for j=i to n: ... 产生 n + (n‑1) + … + 1 = n(n+1)/2,依然是 O(n²)。

Example: n=100, complete nested loops: 10,000 operations. For the triangular loop: 5050 operations. Identify the dominant term.

示例:n=100,完整嵌套循环:10,000 次操作。三角循环:5050 次操作。识别主导项。


11. Error Detection & Correction Overhead | 检错与纠错开销

Hamming code and parity schemes add extra bits to data. For a Hamming code that corrects single‑bit errors, the number of parity bits k for m data bits must satisfy 2ᵏ ≥ m + k + 1. Solve for smallest k. For instance, m = 8 data bits: try k=3 → 8 ≤ 8? 2³=8, m+k+1=12, fails. k=4 → 16 ≥ 13, works. So 4 parity bits are needed, total codeword length = 12 bits.

汉明码和奇偶校验方案为数据添加额外比特。对于可纠正单比特错误的汉明码,数据位 m 所需的校验位 k 须满足 2ᵏ ≥ m + k + 1。求最小 k。例如 m = 8 数据位:尝试 k=3 → 8 ≤ 12?2³=8,m+k+1=12,不成立。k=4 → 16 ≥ 13,成立。因此需要 4 个校验位,总码字长 12 位。

For simple parity check, only 1 bit per data block. The overhead percentage = (extra bits / total bits) × 100%.

简单奇偶校验每数据块只需 1 位。开销百分比 = (额外位 / 总位数) × 100%。

Data bits (m) Parity bits (k) Total bits
4 3 7
8 4 12
16 5 21

12. Mixed Calculation Problem | 综合计算题

Examiners often combine topics. For instance:

You record 2 minutes of stereo audio at 44.1 kHz, 16‑bit. The uncompressed file is then compressed to 40% of its original size. You transmit this compressed file over an 8 Mbps connection. Calculate the transmission time. (Use 1 MB = 10⁶ B, 1 Mbps = 10⁶ bps.)

考试常结合多个主题。例如:

录制 2 分钟立体声音频,44.1 kHz,16 位。未压缩文件随后被压缩到原大小的 40%。通过 8 Mbps 连接传输此压缩文件。计算传输时间。(使用 1 MB = 10⁶ B,1 Mbps = 10⁶ bps。)

Solution: Original bits = 44,100 × 16

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