A1.2.4 · Computer fundamentals
A1.2.4 · 计算机基础
Construct and Analyse Truth Tables
构建和分析真值表
A truth table lists every possible combination of inputs and the output for each one. It is the bridge between a problem in words, a Boolean expression and a logic circuit: all three describe the same table.
真值表列出输入的每一种可能组合,以及每一种组合对应的输出。它是一座桥,连接用文字描述的问题、布尔表达式和逻辑电路:这三者描述的是同一张表。
A1's guiding question asks what principles underpin how a computer works. A truth table is the complete, checkable specification of a piece of logic: nothing about the circuit's behaviour is left unsaid.
A1 的引导性问题问的是支撑计算机运行的原理。真值表是一段逻辑的完整、可核对的规格说明:关于这个电路的行为,没有任何一点被漏掉。
Explainer
讲解
Four forms of one thing
同一件事的四种形式
A truth table has one column per input, one column per output (and often extra columns for the outputs of gates partway through), and one row for every possible combination of input values.
真值表每个输入一列,每个输出一列(通常还给中途各个门的输出加额外的列),并且输入值的每一种可能组合占一行。
| Form | What it looks like | This statement asks you to |
|---|---|---|
| Problem description | A sentence: "the alarm sounds if the system is armed and either sensor trips" | Pick the gates it implies |
| Boolean expression | X = A · (B + C) | Read it, and build its truth table |
| Logic circuit | Gates joined by wires | Trace it row by row to a truth table |
| Truth table | Every input row and the output for each | Use it to simplify the expression or design the circuit |
| 形式 | 它长什么样 | 本条考纲要求你 |
|---|---|---|
| 问题描述 | 一句话:"当系统已布防、并且任一传感器被触发时,警报响起" | 选出它所暗示的门 |
| 布尔表达式 | X = A · (B + C) | 读懂它,并构建它的真值表 |
| 逻辑电路 | 用导线连起来的门 | 逐行追踪它,得到真值表 |
| 真值表 | 每一行输入,以及每行对应的输出 | 用它来化简表达式或设计电路 |
Explainer
讲解
How many rows, and in what order
多少行,按什么顺序
With n inputs there are 2n rows: 2 inputs give 4 rows, 3 inputs give 8. Fill the input columns by counting up in binary from all-zeros: the rightmost column alternates 0, 1 every row; the next alternates every two rows; the next every four. That order guarantees every combination appears exactly once.
有 n 个输入就有 2n 行:2 个输入 4 行,3 个输入 8 行。从全 0 开始按二进制递增来填输入列:最右一列每行在 0、1 之间交替;下一列每两行交替一次;再下一列每四行。这个顺序保证每种组合都恰好出现一次。
For anything with more than one gate, give each gate's output its own letter (P, Q) and fill a column for it before combining into the final output.
对于不止一个门的电路,给每个门的输出取一个字母(P、Q),先为它填一列,再组合成最终输出。
Worked example
例题
From a problem to a truth table
从问题到真值表
Problem: a greenhouse roof vent opens when the heater is on and either the humidity is high or the temperature is high. Inputs: H (heater), D (humidity high), T (temperature high). Output: X (vent opens).
问题:温室的屋顶通风口在加热器开着、并且湿度高或温度高时打开。输入:H(加热器)、D(湿度高)、T(温度高)。输出:X(通风口打开)。
Worked example
例题
Simplifying with a Karnaugh map
用卡诺图化简
A Karnaugh map (K-map) rearranges a truth table's output column into a grid so that groups of 1s become visible. Grouping them gives a shorter expression, which means a smaller circuit. Here is X = A’·B·C + A·B·C + A·B·C’.
卡诺图(K-map)把真值表的输出列重新排进一个网格,使一组组的 1 变得直观。把它们分组就得到更短的表达式,也就是更小的电路。这里是 X = A’·B·C + A·B·C + A·B·C’。
Groups hold 1, 2, 4, 8 … cells (a power of 2), form a rectangle or square (never a diagonal), are made as large as possible, may overlap, and the map wraps around its edges. For each group, keep the variables that stay the same across it and drop the ones that change.
每个组含 1、2、4、8 … 个单元(2 的幂),形成矩形或正方形(不能是对角线),尽可能做大,可以重叠,并且卡诺图的边是环绕相连的。对每个组,保留在组内保持不变的变量,去掉发生变化的变量。
Explainer
讲解
The same result by algebra
用代数得到同样的结果
A Karnaugh map is one route to the simplified expression; the Boolean algebra rules are the other. Starting from the same three terms:
卡诺图是通向化简表达式的一条路;布尔代数规则是另一条。从同样的三项出发:
| Step | Working | Rule used |
|---|---|---|
| Start | X = A’·B·C + A·B·C + A·B·C’ | – |
| 1 | = B·C·(A’ + A) + A·B·C’ | Factor out B·C |
| 2 | = B·C·1 + A·B·C’ = B·C + A·B·C’ | A’ + A = 1 (complement) |
| 3 | = B·(C + A·C’) | Factor out B |
| 4 | = B·(C + A) | C + A·C’ = C + A (absorption) |
| Result | X = B·(A + C), which is A·B + B·C | Distribution |
| 步骤 | 推导 | 用到的规则 |
|---|---|---|
| 起始 | X = A’·B·C + A·B·C + A·B·C’ | – |
| 1 | = B·C·(A’ + A) + A·B·C’ | 提取公因子 B·C |
| 2 | = B·C·1 + A·B·C’ = B·C + A·B·C’ | A’ + A = 1(互补律) |
| 3 | = B·(C + A·C’) | 提取公因子 B |
| 4 | = B·(C + A) | C + A·C’ = C + A(吸收律) |
| 结果 | X = B·(A + C),即 A·B + B·C | 分配律 |
Both routes end at the same place. The K-map is faster to do by hand and harder to get wrong; algebra is needed when there are more than four or five variables, where a K-map becomes unwieldy.
两条路都到达同一个地方。卡诺图手算更快、更不容易出错;当变量多于四五个、卡诺图变得笨重时,就需要代数。
Check your understanding
检验你的理解
For X = (A OR C) AND NOT B, what is X when A = 1, B = 0, C = 0?
对于 X = (A OR C) AND NOT B,当 A = 1、B = 0、C = 0 时,X 是多少?
Common mistake
常见错误
RecurringLabelling a K-map's columns in plain binary order (00, 01, 10, 11) instead of Gray code (00, 01, 11, 10). Gray code changes only one bit between neighbours, which is exactly what lets adjacent 1s be grouped; plain binary order breaks the grouping and gives a wrong simplification. A second slip: leaving rows out of a truth table. With 3 inputs there must be 8 rows, always, even the ones where the output is 0.
反复出现把卡诺图的列按普通二进制顺序(00、01、10、11)标注,而不是格雷码(00、01、11、10)。格雷码在相邻两列之间只改变一个位,这正是让相邻的 1 能被分组的原因;普通二进制顺序会破坏分组,给出错误的化简。第二个错误:真值表漏行。3 个输入就必须有 8 行,永远如此,连输出为 0 的行也要写。
Wrong: "I labelled the K-map columns 00, 01, 10, 11 like normal binary counting, then grouped the 1s in the first two columns."
错误: "我把卡诺图的列按普通二进制计数标成 00、01、10、11,然后把前两列的 1 分成一组。"
Right: "K-map columns go 00, 01, 11, 10 (Gray code) so neighbouring columns differ in one variable only. Adjacent 1s can then be grouped, and the map wraps around, so the last column is also next to the first."
正确: "卡诺图的列按 00、01、11、10(格雷码)排列,使相邻列只在一个变量上不同。这样相邻的 1 才能分组,而且卡诺图边缘环绕相连,所以最后一列也和第一列相邻。"
Revision questions
复习题
Specimen-paper style. Write an answer, then reveal the marking points and mark yourself.
采用样卷风格。写下答案,然后展开评分要点给自己打分。
[2]Construct a truth table for X = A AND NOT B.
[2]为 X = A AND NOT B 构建真值表。
Marking points
评分要点
- Completed truth table for X = A AND NOT B:
A B X 0 0 0 0 1 0 1 0 1 1 1 0 - NOT B inverts B first, then it is ANDed with A, so X is 1 only when A = 1 and B = 0.
- X = A AND NOT B 的完整真值表:
A B X 0 0 0 0 1 0 1 0 1 1 1 0 - 先用 NOT B 对 B 取反,再与 A 做 AND,所以只有当 A = 1 且 B = 0 时 X 才为 1。
[3]Build the truth table for X = (A OR C) AND (NOT B), including one intermediate column for the OR gate.
[3]为表达式 X = (A OR C) AND (NOT B) 构建真值表,使用一个中间列。
Marking points
评分要点
- Completed truth table, with the intermediate column P = A OR C:
A B C P X 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 1 0 1 1 1 1 1 0 1 0 1 1 1 1 0 - X = P AND NOT B, so X is 1 only when B = 0 and at least one of A, C is 1.
- 完整真值表,含中间列 P = A OR C:
A B C P X 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 1 0 1 1 1 1 1 0 1 0 1 1 1 1 0 - X = P AND NOT B,所以只有当 B = 0 且 A、C 中至少一个为 1 时 X 才为 1。
[3]A pump should run only when the tank is not full and either the timer is active or the manual switch is on. Draw up the full truth table for the system.
[3]一个水泵只有在水箱未满、并且定时器已启动或手动开关打开时才运行。为这个系统构建真值表。
Marking points
评分要点
- Inputs: F (tank full), T (timer active), M (manual switch on). Output: R (pump runs). R = (NOT F) AND (T OR M).
F T M R 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 0 - (R is 1 only when F = 0 and at least one of T, M is 1.)
- 输入:F(水箱满)、T(定时器激活)、M(手动开关开)。输出:R(泵运行)。R = (NOT F) AND (T OR M)。
F T M R 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 0 - (只有当 F = 0 且 T、M 中至少一个为 1 时,R 才为 1。)
[4]Draw the Karnaugh map for X = A’·B·C’ + A’·B·C + A·B·C and write the simplified expression.
[4]为 X = A’·B·C’ + A’·B·C + A·B·C 画卡诺图,并写出化简后的表达式。
Marking points
评分要点
- The three terms are A'BC', A'BC and ABC.
- Group A'BC' with A'BC (C changes, A' and B stay): gives A'B.
- Group A'BC with ABC (A changes, B and C stay): gives BC.
- Simplified expression: X = A'B + BC, which is B.(A' + C).
- 三个项是 A'BC'、A'BC 和 ABC。
- 把 A'BC' 与 A'BC 分为一组(C 变化,A' 和 B 不变):得到 A'B。
- 把 A'BC 与 ABC 分为一组(A 变化,B 和 C 不变):得到 BC。
- 化简后的表达式:X = A'B + BC,即 B.(A' + C)。
[3]Explain why a Karnaugh map's column headings use Gray code rather than plain binary counting.
[3]解释为什么卡诺图的列标题使用格雷码而不是普通的二进制计数。
Marking points
评分要点
- Gray code changes only one variable between neighbouring cells.
- This is what makes cells that are next to each other on the map also differ by exactly one variable, so adjacent 1s can be grouped and one variable dropped.
- With plain binary counting (00, 01, 10, 11) the second and third columns differ in two variables, so grouping them would not correspond to a valid simplification.
- 格雷码在相邻单元之间只改变一个变量。
- 这使得图上彼此相邻的单元也恰好只差一个变量,所以相邻的 1 可以被分组并去掉一个变量。
- 用普通二进制计数(00、01、10、11)时,第二列和第三列相差两个变量,所以把它们分组并不对应一个有效的化简。
Flashcards
记忆卡片
Active recall for this statement’s key terms.
针对本条考纲陈述关键术语的主动回忆练习。
Keep this statement’s practice with you
把这条考纲陈述的练习保存下来
Free account: unlock every revision question and flashcard for A1.2.4, and every other IB CS 2027 statement.
免费账户:解锁 A1.2.4 以及所有其他 IB CS 2027 考纲陈述的全部复习题和记忆卡片。