📚 IB Computer Science: Calculation Drill | IB 计算机:计算题专项训练
IB Computer Science examinations often include numerical questions that test your ability to apply concepts precisely – from binary arithmetic to algorithm efficiency. This article presents a structured drill covering the most common calculation-based topics, complete with worked examples and step-by-step reasoning.
IB 计算机科学考试中常出现需要精确计算的应用题,涉及二进制运算、算法效率等。本文提供一套结构化的计算题专项训练,涵盖最常见题型,并配有详细示例与步骤讲解,帮助你在计算类题目上稳拿分数。
1. Binary and Hexadecimal Conversion | 二进制与十六进制转换
To convert a binary number to hexadecimal, group the bits into nibbles of four starting from the right (least significant bit). Each group is then replaced by its hex digit equivalent.
将二进制数转换为十六进制,从右侧最低位开始将二进制位每4位分为一组,每一组用对应的十六进制数字替换。
Example: Convert 11010110₂ to hex. Group as 1101 0110. 1101₂ = D₁₆, 0110₂ = 6₁₆, giving D6₁₆.
示例:将 11010110₂ 转为十六进制。分组为 1101 和 0110。1101₂ = D₁₆,0110₂ = 6₁₆,结果为 D6₁₆。
To convert hexadecimal to binary, reverse the process: replace each hex digit with its 4‑bit binary equivalent. For instance, A3₁₆ = 1010 0011₂.
将十六进制转为二进制则反向操作:每个十六进制数字替换为对应的4位二进制。例如 A3₁₆ = 1010 0011₂。
Decimal to binary conversion uses successive division by 2, recording remainders. Convert 53₁₀ to binary: 53 ÷ 2 = 26 r1, 26 ÷ 2 = 13 r0, 13 ÷ 2 = 6 r1, 6 ÷ 2 = 3 r0, 3 ÷ 2 = 1 r1, 1 ÷ 2 = 0 r1. Reading remainders upwards gives 110101₂.
十进制转二进制采用除2取余法。53₁₀ 转二进制:53 ÷ 2 = 26 余1,26 ÷ 2 = 13 余0,13 ÷ 2 = 6 余1,6 ÷ 2 = 3 余0,3 ÷ 2 = 1 余1,1 ÷ 2 = 0 余1。余数从下往上读得 110101₂。
2. Two’s Complement Representation | 补码表示与运算
In an 8‑bit two’s complement system, the most significant bit indicates the sign (0 for positive, 1 for negative). The representable range is −128 to +127.
在8位补码系统中,最高位表示符号(0正1负),可表示范围为 −128 至 +127。
To find the two’s complement of a negative integer, start with the binary of its magnitude, invert all bits, then add 1. For −23: magnitude 23 = 00010111₂, invert → 11101000, add 1 → 11101001₂.
求负整数的补码:先写出其绝对值的二进制,所有位取反后加1。如 −23:绝对值 23 = 00010111₂,取反得 11101000,加1得 11101001₂。
Binary addition in two’s complement follows normal rules, with overflow ignored if it falls outside the representable range. For example, −35 + 22 in 8‑bit: −35 is 11011101₂, 22 is 00010110₂, sum = 11110011₂. This is negative (MSB=1); to check its magnitude, invert and add 1 → 00001101₂ = 13, so the result is −13.
补码加法按普通二进制加法规则进行,超出表示范围的溢出忽略。例如 −35 + 22 在8位系统:−35 为 11011101₂,22 为 00010110₂,和为 11110011₂。结果为负(最高位1),验证其值:取反加1得 00001101₂ = 13,故结果为 −13。
3. Logic Gates and Truth Tables | 逻辑门与真值表
Given a Boolean expression such as F = (A AND B) OR (NOT C), a truth table exhaustively lists all input combinations and calculates the output.
对于给定的布尔表达式,如 F = (A AND B) OR (NOT C),真值表列出所有输入组合并计算相应的输出。
| A | B | C | A AND B | NOT C | F |
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 1 |
The truth table shows that F is 1 when C is 0, regardless of A and B, or when both A and B are 1 while C is 1. This is a typical pattern that can be simplified using a Karnaugh map.
真值表表明,当 C 为 0 时无论 A、B 取值 F 都为 1,此外在 C=1 且 A=B=1 时 F 也为 1。这是可用卡诺图化简的典型模式。
4. Boolean Algebra Simplification | 布尔代数化简
The absorption law states A + A·B = A. Proof: A + A·B = A·(1 + B) = A·1 = A.
吸收律:A + A·B = A。证明:A + A·B = A·(1 + B) = A·1 = A。
Simplify (A + B)(A + C). Start by expanding: (A + B)(A + C) = A·A + A·C + B·A + B·C = A + A·C + A·B + B·C. Then factor A: = A·(1 + C + B) + B·C = A + B·C.
化简 (A + B)(A + C)。展开
Published by TutorHao | IB Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导