📚 IB CIE Computer Science: Calculation Practice Problems | IB CIE 计算机:计算题专项训练
Calculation questions form a significant part of the IB and CIE Computer Science examinations. These problems test your ability to apply theoretical knowledge to numerical scenarios, from binary conversions to performance metrics. This article provides a structured practice set covering the most common calculation topics in the syllabus, with step‑by‑step explanations and representative examples. Work through each section carefully to build both speed and accuracy.
计算题在 IB 和 CIE 计算机科学考试中占有重要地位。这些题目考查你把理论知识应用于数值场景的能力,从二进制转换到性能指标均有涉及。本文提供了一套结构化的专项训练,覆盖考纲中最常见的计算主题,并配有逐步讲解和典型例题。仔细完成每个部分,提高解题速度和准确性。
1. Binary and Decimal Conversions | 二进制与十进制转换
Converting between binary (base‑2) and decimal (base‑10) is fundamental. A binary number such as 1011₂ means 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 11₁₀. To convert a decimal integer to binary, repeatedly divide by 2 and record the remainders from bottom to top. For decimal fractions, multiply the fractional part by 2 repeatedly, taking the integer part each time.
二进制(基数为2)与十进制(基数为10)之间的转换是基础。二进制数 1011₂ 表示 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 11₁₀。将十进制整数转换为二进制时,反复除以2并从下往上记录余数。对于十进制小数,则不断将小数部分乘以2,每次取出整数部分。
Example: Convert 156.375₁₀ to binary (up to 8 fractional bits).
Integer part: 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 → 10011100₂.
Fractional part: 0.375×2 = 0.75 (int 0); 0.75×2 = 1.5 (int 1); 0.5×2 = 1.0 (int 1) → .011₂.
Result: 10011100.011₂.
例题:将 156.375₁₀ 转换为二进制(小数部分保留8位)。
整数部分: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₂。
小数部分:0.375×2 = 0.75(整数0);0.75×2 = 1.5(整数1);0.5×2 = 1.0(整数1)→ .011₂。
结果:10011100.011₂。
2. Hexadecimal Conversions | 十六进制转换
Hexadecimal (base‑16) uses digits 0‑9 and letters A‑F. Each hex digit represents exactly 4 bits, which makes conversion from binary straightforward. Group binary digits into nibbles (4 bits) starting from the binary point, then replace each nibble with its hex equivalent.
十六进制(基数为16)使用数字0‑9和字母A‑F。每个十六进制位恰好代表4个二进制位,因此从二进制转换非常简单。从二进制小数点开始,将二进制位每4位一组分组,然后将每个组替换为对应的十六进制数字。
Example: Convert 10111101.1101₂ to hex. Group: 1011 1101 . 1101 → 11 (B), 13 (D), . 13 (D) → BD.D₁₆. Conversely, A2.F₁₆ = 1010 0010 . 1111₂.
例题:将 10111101.1101₂ 转换为十六进制。分组:1011 1101 . 1101 → 11 (B), 13 (D), . 13 (D) → BD.D₁₆。反过来,A2.F₁₆ = 1010 0010 . 1111₂。
3. 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 carry 1, and 1+1+carry=1 carry 1. When adding two 8‑bit signed numbers in two’s complement, overflow occurs if the carry into the most significant bit (MSB) is different from the carry out of the MSB. Overflow indicates that the result is outside the representable range.
二进制加法遵循与十进制加法相同的规则:0+0=0,0+1=1,1+0=1,1+1=0 进位1,1+1+进位=1 进位1。当使用二进制补码表示的两个8位有符号数相加时,如果最高有效位(MSB)的进位输入与进位输出不同,则发生溢出。溢出表明结果超出了可表示的范围。
Example: Add 01001101 (77) and 00111010 (58) → result 10000111 (135). In 8‑bit two’s complement, 135 is outside the range –128 to 127, so overflow occurs. Check: carry into MSB = 1, carry out = 0 → different → overflow.
例题:计算 01001101 (77) + 00111010 (58) → 结果为 10000111 (135)。在8位补码中,135超出 –128 到 127 的范围,因此发生溢出。检查:MSB进位输入 = 1,进位输出 = 0 → 不同 → 溢出。
4. Two’s Complement for Negative Numbers | 二进制补码表示负数
Two’s complement is the standard method for representing signed integers. To obtain the negative of a number, invert all bits (one’s complement) and add 1. For an n‑bit number, the most negative value is –2ⁿ⁻¹ and the most positive is 2ⁿ⁻¹–1. Always specify the number of bits used.
二进制补码是表示有符号整数的标准方法。要获得一个数的负数,先将所有位取反(反码)再加1。对于n位数字,最小的负数为 –2ⁿ⁻¹,最大的正数为 2ⁿ⁻¹–1。务必注明使用的位数。
Example: Represent –35 in 8‑bit two’s complement. Positive 35 = 00100011₂. Invert: 11011100. Add 1: 11011101. So –35₁₀ = 11011101₂ in 8‑bit two’s complement. The decimal value: –2⁷ + 2⁶ + 2⁴ + 2³ + 2² + 2⁰ = –128 + 64 + 16 + 8 + 4 + 1 = –35.
例题:用8位补码表示 –35。正数35 = 00100011₂。取反:11011100。加1:11011101。因此 –35₁₀ 在8位补码中为 11011101₂。十进制验证:–2⁷ + 2⁶ + 2⁴ + 2³ + 2² + 2⁰ = –128 + 64 + 16 + 8 + 4 + 1 = –35。
5. Logic Gates and Truth Tables | 逻辑门与真值表
Logic gates form the building blocks of digital circuits. You must be able to complete truth tables for combinations of AND, OR, NOT, NAND, NOR, XOR, and XNOR gates. For a circuit with n inputs, the truth table has 2ⁿ rows. Calculate the output column by column, following the circuit diagram.
逻辑门是数字电路的基础构件。你必须能够填写由与门、或门、非门、与非门、或非门、异或门、同或门组成的组合电路的真值表。对于有n个输入的电路,真值表有2ⁿ行。按照电路图逐列计算输出。
Example: For a circuit: Q = NOT (A XOR B) AND C. Inputs A, B, C. Write all 8 combinations. Compute A XOR B, then NOT, then AND with C. The final column shows Q.
例题:电路:Q = NOT (A XOR B) AND C。输入 A, B, C。写出所有8种组合。计算 A XOR B,然后取反,再与 C 进行 AND 运算。最后一列为 Q。
| A | B | C | A XOR B | NOT | Q |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 1 | 0 | 0 |
| 1 | 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 1 | 1 |
6. Boolean Algebra Simplification | 布尔代数化简
Boolean algebra uses laws such as commutative, associative, distributive, De Morgan’s laws, and absorption to simplify logic expressions. Simplifying reduces the number of gates needed in a circuit. You may be asked to prove identities or simplify an expression to a given number of terms/literals.
布尔代数利用交换律、结合律、分配律、德摩根定律和吸收律等规则来简化逻辑表达式。化简可减少电路所需的门数量。考试可能要求证明恒等式或将表达式化简为指定数量的项/文字。
Example: Simplify A·B + A·(B+C) + B·(B+C).
A·B + A·B + A·C + B·B + B·C = A·B + A·C + B + B·C (since A·B + A·B = A·B, and B·B = B)
= A·B + A·C + B (absorption: B + B·C = B)
= B + A·C (absorption: B + A·B = B).
Final expression: B + A·C.
例题:化简 A·B + A·(B+C) + B·(B+C)。
A·B + A·B + A·C + B·B + B·C = A·B + A·C + B + B·C(因为 A·B + A·B = A·B,且 B·B = B)
= A·B + A·C + B(吸收律:B + B·C = B)
= B + A·C(吸收律:B + A·B = B)。
最终表达式:B + A·C。
7. Network: IP Addresses and Subnet Masks | 网络:IP地址与子网掩码
An IPv4 address is a 32‑bit number, typically written in dotted‑decimal notation (e.g., 192.168.1.10). A subnet mask (e.g., 255.255.255.0) determines which portion is the network ID and which is the host ID. Performing a bitwise AND between the IP and the subnet mask gives the network address. The number of hosts per subnet is 2^(number of host bits) – 2 (excluding network and broadcast addresses).
IPv4地址是一个32位数字,通常以点分十进制表示(如 192.168.1.10)。子网掩码(如 255.255.255.0)确定哪一部分是网络ID,哪一部分是主机ID。将IP地址与子网掩码进行按位与运算即可得到网络地址。每个子网的主机数量为 2^(主机位数) – 2(排除网络地址和广播地址)。
Example: IP 192.168.5.130/26 (mask 255.255.255.192). Subnet mask in binary: 11111111.11111111.11111111.11000000. Host bits = 6, so number of usable hosts = 2⁶ – 2 = 62. Network address: 192.168.5.130 AND 255.255.255.192 = 192.168.5.128. Broadcast: 192.168.5.191.
例题:IP 192.168.5.130/26(子网掩码 255.255.255.192)。二进制子网掩码:11111111.11111111.11111111.11000000。主机位数 = 6,因此可用主机数 = 2⁶ – 2 = 62。网络地址:192.168.5.130 AND 255.255.255.192 = 192.168.5.128。广播地址:192.168.5.191。
8. Sound Sampling Rate and File Size | 声音采样率与文件大小
Digital sound is stored as a series of samples. File size (in bits) = sample rate (Hz) × bit depth × number of channels × duration (seconds). Typical sample rates: 44.1 kHz for CD quality. Bit depth is usually 16 or 24 bits. Channel count: 1 for mono, 2 for stereo.
数字声音存储为一系列采样值。文件大小(位)= 采样率(Hz)× 位深度 × 通道数 × 时长(秒)。典型的采样率:CD品质为44.1 kHz。位深度通常为16或24位。通道数:单声道为1,立体声为2。
Example: A 3‑minute stereo recording at 44.1 kHz, 16‑bit. File size = 44100 × 16 × 2 × 180 seconds = 254,016,000 bits. Convert to bytes: /8 = 31,752,000 bytes ≈ 30.3 MB (divide by 1024² for MiB).
例题:一段3分钟的立体声录音,采样率44.1 kHz,位深度16位。文件大小 = 44100 × 16 × 2 × 180秒 = 254,016,000位。转换为字节:除以8得到31,752,000字节 ≈ 30.3 MB(除以1024²得到MiB)。
9. Image File Size Calculation | 图像文件大小计算
Bitmap images store pixels individually. File size (bits) = image width (px) × image height (px) × colour depth (bits per pixel). Colour depth depends on the number of colours: e.g., 8 bits for 256 colours, 24 bits for true colour. Remember to account for metadata if specified, though usually only the pixel data is calculated. Some questions may ask for kilobytes or megabytes.
位图图像单独存储每个像素。文件大小(位)= 图像宽度(像素)× 图像高度(像素)× 颜色深度(每像素位数)。颜色深度取决于颜色数量:例如256色为8位,真彩色为24位。若题目指定元数据,则需加上,但通常只计算像素数据部分。有些题目可能要求以千字节或兆字节为单位。
Example: An image of 1024 × 768 pixels with 16‑bit colour. File size = 1024 × 768 × 16 = 12,582,912 bits. In kB: 12,582,912 / (8×1024) = 1536 kB = 1.5 MB (if 1000 bytes per kB, need to check exam convention).
例题:一张1024×768像素、16位色彩的图像。文件大小 = 1024 × 768 × 16 = 12,582,912位。以kB计:12,582,912 / (8×1024) = 1536 kB = 1.5 MB(注意考试通常使用1024还是1000)。
10. Data Compression Ratios | 数据压缩比
Compression ratio = original size / compressed size. It indicates how much the file size has been reduced. Alternatively, space saving = (1 – compressed/original) × 100%. Lossy compression (like JPEG, MP3) reduces file size by discarding some data, while lossless (like PNG, ZIP) preserves all original information. Calculate ratios for both scenarios as required.
压缩比 = 原始大小 / 压缩后大小。它表示文件大小缩小的程度。或者,空间节省率 = (1 – 压缩后/原始) × 100%。有损压缩(如JPEG、MP3)通过丢弃部分数据减小文件,无损压缩(如PNG、ZIP)则保留所有原始信息。根据要求计算相应的比例。
Example: A 24 MB video file is compressed to 3 MB. Compression ratio = 24/3 = 8:1. Space saving = (1 – 3/24)×100% = 87.5%. If the video was compressed losslessly, the ratio remains 8:1, but the quality is unchanged.
例题:一个24 MB的视频文件被压缩到3 MB。压缩比 = 24/3 = 8:1。空间节省率 = (1 – 3/24)×100% = 87.5%。若为无损压缩,压缩比仍为8:1,但质量不变。
11. Processor Performance and Clock Speed | 处理器性能与时钟速度
Processor performance can be quantified by the execution time formula: Execution time = (Number of instructions × CPI) / Clock rate. CPI (cycles per instruction) and clock rate (in Hz) determine how fast a program runs. Sometimes you are given instruction counts for different types and their respective CPIs – calculate the total cycles and then divide by clock frequency.
处理器性能可用执行时间公式量化:执行时间 = (指令数 × CPI) / 时钟频率。CPI(每指令周期数)和时钟频率(Hz)决定程序运行速度。有时题目会给出不同类型指令的数量及其各自CPI——计算总周期数,然后除以时钟频率。
Example: A program has 2×10⁹ instructions, with CPI = 1.5, and a clock rate of 3 GHz. Execution time = (2×10⁹ × 1.5) / (3×10⁹ Hz) = 3×10⁹ / 3×10⁹ = 1 second. If the clock rate is increased to 4 GHz, time = 3×10⁹ / 4×10⁹ = 0.75 s.
例题:某个程序有2×10⁹条指令,CPI = 1.5,时钟频率3 GHz。执行时间 = (2×10⁹ × 1.5) / (3×10⁹ Hz) = 3×10⁹ / 3×10⁹ = 1秒。若时钟频率提升至4 GHz,时间 = 3×10⁹ / 4×10⁹ = 0.75秒。
12. Cache Hit Rate and Average Access Time | 缓存命中率与平均访问时间
The average memory access time (AMAT) = Hit time + Miss rate × Miss penalty. Hit rate = fraction of accesses found in cache; miss rate = 1 – hit rate. In a two‑level cache system, you may need to compute the overall AMAT. Always express hit/miss rates as decimals (e.g., 95% = 0.95).
平均内存访问时间(AMAT)= 命中时间 + 缺失率 × 缺失代价。命中率 = 在缓存中找到的访问比例;缺失率 = 1 – 命中率。在二级缓存系统中,可能需要计算总体AMAT。始终将命中/缺失率表示为小数(如95% = 0.95)。
Example: A cache has hit time = 1 ns, miss penalty = 50 ns, hit rate = 0.98. AMAT = 1 + (0.02 × 50) = 1 + 1 = 2 ns. For a two‑level cache: L1 hit time = 1 ns, L1 miss rate = 0.05; L2 hit time = 5 ns, L2 miss rate = 0.1; main memory access = 100 ns. AMAT = 1 + (0.05 × (5 + 0.1×100)) = 1 + 0.05×(5+10) = 1 + 0.75 = 1.75 ns.
例题:某缓存命中时间 = 1 ns,缺失代价 = 50 ns,命中率 = 0.98。AMAT = 1 + (0.02 × 50) = 1 + 1 = 2 ns。对于二级缓存:L1命中时间 = 1 ns,L1缺失率 = 0.05;L2命中时间 = 5 ns,L2缺失率 = 0.1;主存访问 = 100 ns。AMAT = 1 + (0.05 × (5 + 0.1×100)) = 1 + 0.05×(5+10) = 1 + 0.75 = 1.75 ns。
Published by TutorHao | IB CIE Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导