Logic circuits · 逻辑电路
| English | 中文 | Pinyin · 拼音 |
|---|---|---|
| logic circuit/ˈlɒdʒɪk ˈsɜːkɪt/ | 逻辑电路 | luó jí diàn lù |
| Boolean expression/ˈbuːlɪən ekˈspreʃn/ | 布尔表达式 | bù ěr biǎo dá shì |
| problem statement/ˈprɒbləm ˈsteɪtmənt/ | 问题陈述 | wèn tí chén shù |
| truth table/truːθ ˈteɪbl/ | 真值表 | zhēn zhí biǎo |
| sum of products/sʌm ɒv ˈprɒdʌkts/ | 积之和 | jī zhī hé |
| half adder/hɑːf ˈædə/ | 半加器 | bàn jiā qì |
Three sensors, two gates, one decision
- A microwave oven heats only when the door is closed and the start button has been pressed and the timer has not reached zero.
- Three sensors give three 0/1 signals. Two AND gates combine them into one signal that switches the magnetron. Open the door and the output drops to 0 at once.
- Every safety interlock, every alarm and every processor instruction is a decision like this, built from the six gates of the last lesson.
- This lesson is about building and reading those circuits, and moving between the four ways of writing the same decision.
三个传感器、两个门、一个决定
- 微波炉只有在门关上并且已按下启动键并且计时器还没到零时才加热。
- 三个传感器给出三个 0/1 信号。两个 AND 门把它们合成一个切换磁控管的信号。打开门,输出立刻降为 0。
- 每一个安全联锁、每一个警报、每一条处理器指令,都是像这样由上一课的六个门搭出来的决定。
- 这一课讲怎样搭建和读懂这些电路,以及怎样在同一个决定的四种写法之间转换。
Four views of one function
- A logic circuit 逻辑电路 is a network of gates that carries out a Boolean expression 布尔表达式.
- The same function can be written as a problem statement 问题陈述 in English, as an expression, as a circuit diagram, or as a truth table 真值表. The exam asks you to move in every direction between them.
- The paper writes expressions in words,
X = (A AND NOT B) OR (B AND C), and accepts the algebraic form $X = A\overline{B} + BC$, where a dot or nothing is AND, a plus is OR and a bar is NOT. Use whichever the question uses.
Gates wired together to carry out one Boolean expression
同一个函数的四种视图
- 逻辑电路(logic circuit)是执行一个布尔表达式(Boolean expression)的门网络。
- 同一个函数可以写成英文的问题陈述(problem statement)、一个表达式、一张电路图,或一张真值表(truth table)。考试要求你在它们之间朝每个方向转换。
- 试卷用文字写表达式,
X = (A AND NOT B) OR (B AND C),也接受代数形式 $X = A\overline{B} + BC$,其中点或不写是 AND,加号是 OR,横线是 NOT。题目用哪种,你就用哪种。

连接起来执行一个布尔表达式的门
Expression to circuit
- Draw one gate per operator, starting from the innermost brackets.
- For
X = (A AND B) OR (NOT C): an AND gate on A and B, a NOT gate on the C wire, and an OR gate combining the two results. - Inputs on the left, the single output on the right, every line ending at a gate input or the output, and the output labelled X.
One gate for each operator in the expression
从表达式到电路
- 从最里层的括号开始,每个运算符画一个门。
- 对
X = (A AND B) OR (NOT C):A 和 B 进一个 AND 门,C 的线上一个 NOT 门,再用一个 OR 门合并两个结果。 - 输入在左边,唯一的输出在右边,每条线都终止于某个门的输入或输出端,并把输出标为 X。

表达式里每个运算符对应一个门
Logic circuits · 逻辑电路
gates combine into circuits · 门组合成电路
Each gate has a fixed rule; chaining them builds every circuit — start with one gate. · 每个门有一个固定的规则;把它们链接起来构建每个电路——从一个门开始。
For · 支持 $X = (A \cdot B) + \overline{C}$ with $A=1, B=1, C=1$, what is $X$? · 对于 $X = (A \cdot B) + \overline{C}$,当 $A=1, B=1, C=1$ 时,$X$ 是多少?
$A \cdot B = 1$, and $\overline{C} = 0$. $X = 1 + 0 = 1$. · $A \cdot B = 1$,而 $\overline{C} = 0$。$X = 1 + 0 = 1$。
Worked example: circuit to expression
- Work forwards from the inputs and label every intermediate output.
- In the circuit below, B passes through a NOT gate. A and NOT B feed an AND gate: call its output P, so
P = A AND NOT B. B and C feed a second AND gate:Q = B AND C. - P and Q feed the OR gate, so
X = P OR Q = (A AND NOT B) OR (B AND C). - Labelling P and Q is not decoration. It is what lets you fill the truth table one gate at a time.
Label every intermediate output before you write the expression
例题:从电路到表达式
- 从输入向前推,并给每个中间输出加标签。
- 在下面的电路里,B 经过一个 NOT 门。A 和 NOT B 进入一个 AND 门:把它的输出叫 P,于是
P = A AND NOT B。B 和 C 进入第二个 AND 门:Q = B AND C。 - P 和 Q 进入 OR 门,所以
X = P OR Q = (A AND NOT B) OR (B AND C)。 - 标出 P 和 Q 不是装饰。正是它让你能一个门一个门地填真值表。

写表达式之前,给每个中间输出加标签
In the worked circuit, the second AND gate's output is Q = B AND ____. · 在例题的电路中,第二个 AND 门的输出是 Q = B AND ____。
B and C feed the lower AND gate. Labelling that output Q lets the truth table be filled one gate at a time. · B 和 C 进入下面的 AND 门。把这个输出标为 Q,真值表就能一个门一个门地填。
Circuit to truth table
- For $n$ inputs there are $2^{n}$ rows: two inputs give 4, three give 8, four give 16. List them in binary counting order.
- Give the table a column for each intermediate output as well as the final one, so every row is checked one gate at a time.
- Fill the columns left to right: first the NOT, then each AND, then the OR.
从电路到真值表
- $n$ 个输入有 $2^{n}$ 行:两个输入 4 行,三个 8 行,四个 16 行。按二进制计数顺序列出它们。
- 除了最终输出,也给每个中间输出一列,这样每一行都能一个门一个门地检查。
- 从左到右填列:先 NOT,再每个 AND,然后 OR。
How many rows does a truth table have for a circuit with 3 inputs? · 一个有 3 个输入的电路的真值表有多少行?
$2^n$ rows; for 3 inputs, $2^3 = 8$. · $2^n$ 行;对于 3 个输入,$2^3 = 8$。
How many rows for 4 inputs? · 4 个输入有多少行?
$2^4 = 16$ rows. · $2^4 = 16$ 行。
Worked example: the eight rows
- The circuit from the worked example above, with columns for NOT B, P, Q and X:
| A | B | C | NOT B | P | Q | X |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 0 | 1 | 1 |
- X is 1 in four of the eight rows. Check any one against the expression: row 1 0 0 has A = 1 and NOT B = 1, so P = 1, so X = 1.
例题:八行
- 上面例题中的电路,带有 NOT B、P、Q 和 X 各列:
| A | B | C | NOT B | P | Q | X |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 0 | 1 | 1 |
- 八行中有四行 X 为 1。随便拿一行对照表达式检查:行 1 0 0 有 A = 1 且 NOT B = 1,所以 P = 1,所以 X = 1。
For · 支持 X = (A AND NOT B) OR (B AND C), which of these input rows give X = 1? Select all · 所有 that apply. · 对 X = (A AND NOT B) OR (B AND C),以下哪些输入行给出 X = 1?选出所有适用的。
Row 011 makes Q = 1; row 100 makes P = 1. In row 110, B = 1 kills P and C = 0 kills Q; in row 001 both terms are 0. · 行 011 使 Q = 1;行 100 使 P = 1。行 110 中 B = 1 让 P 为 0、C = 0 让 Q 为 0;行 001 两项都为 0。
Truth table to expression: sum of products
- Sum of products 积之和: for each row whose output is 1, write an AND of the inputs, putting NOT on any input that is 0 in that row. Then OR those terms together.
- A table that is 1 only on (A = 0, B = 1) and (A = 1, B = 0) gives
(NOT A AND B) OR (A AND NOT B), which is exactly A XOR B. - Simplify only if the question asks; the unsimplified sum of products earns the marks.
从真值表到表达式:积之和
- 积之和(sum of products):对每个输出为 1 的行,写出各输入的 AND,该行中为 0 的输入加上 NOT。然后把这些项用 OR 连起来。
- 只在 (A = 0, B = 1) 和 (A = 1, B = 0) 为 1 的表给出
(NOT A AND B) OR (A AND NOT B),正好就是 A XOR B。 - 只有题目要求时才化简;未化简的积之和就能拿到分。
In the sum-of-products method, for each row whose output is 1 you write: · 在积之和方法中,对于每个输出是 1 的行,你写:
Each 1-row becomes an AND term (NOT the 0 inputs); you then OR all those terms together. · 每个 1 行变成一个 AND 项(对 0 输入取 NOT);你然后把所有那些项 OR 在一起。
In sum-of-products, you OR together one AND-term for every row whose output is 1. · 在积之和中,你为每个输出是 1 的行 OR 一个 AND 项。
Each output-1 row becomes an AND term (NOT-ing the 0 inputs); ORing those terms gives an expression that is 1 on exactly those rows. · 每个输出 1 的行变成一个 AND 项(对 0 输入取 NOT);把那些项 OR 起来给出一个恰好在那些行为 1 的表达式。
The half adder
- Adding two bits gives a sum bit and a carry bit: 1 + 1 = 10 in binary.
- The sum column is 0, 1, 1, 0, which is XOR. The carry column is 0, 0, 0, 1, which is AND. Two gates make a half adder 半加器.
- It is the standard example of reading gates straight off a truth table, and the first piece of every processor's arithmetic unit.
Each input pair flows through the gates: XOR gives the sum, AND gives the carry, so 1 + 1 = 10
半加器
- 两个比特相加得到一个和位和一个进位位:二进制中 1 + 1 = 10。
- 和列是 0、1、1、0,这是 XOR。进位列是 0、0、0、1,这是 AND。两个门构成一个半加器(half adder)。
- 它是直接从真值表读出门的标准例子,也是每个处理器算术单元的第一块积木。
每对输入流过两个门:XOR 给出和,AND 给出进位,所以 1 + 1 = 10
Half adder · 半加器
Wire XOR and AND to the same two inputs: XOR gives the sum bit, AND gives the carry. Click A and B. · 把 XOR 和 AND 接到相同的两个输入:XOR 给出和位,AND 给出进位。点击 A 和 B。
In a half adder, which gate produces the carry bit? · 在半加器中,哪个门产生进位位?
The carry is 1 only when both bits are 1, which is AND. The sum is 1 when the bits differ, which is XOR. · 只有两个比特都为 1 时进位才为 1,这是 AND。比特不同时和为 1,这是 XOR。
From a problem statement
- Turn the English into Boolean one clause at a time before drawing anything.
- "A and B" is
A AND B. "A or B, or both" isA OR B. "exactly one of A and B" isA XOR B. - "neither A nor B" is
A NOR B. "not both" isA NAND B. "unless" usually means AND NOT.
从问题陈述出发
- 画任何东西之前,先把英文一句一句转成布尔式。
- "A 且 B"是
A AND B。"A 或 B,或两者"是A OR B。"A 和 B 中恰好一个"是A XOR B。 - "A 和 B 都不"是
A NOR B。"不同时"是A NAND B。"除非"通常意味着 AND NOT。
Match each English phrase to the single gate that implements it. · 把每个英语短语与实现它的单个门配对。
both = AND, differ = XOR, neither = NOR, not-both = NAND. · 都 = AND,不同 = XOR,都不 = NOR,不是两者都 = NAND。
Worked example: a machine alarm
- An alarm X sounds when the guard is open (A = 1) and either the motor is running (B = 1) or the temperature is high (C = 1).
- "Either B or C" is
B OR C. "A and that" isX = A AND (B OR C). The brackets around the OR are essential. - X = 1 needs A = 1 and at least one of B, C equal to 1: the rows (1, 0, 1), (1, 1, 0) and (1, 1, 1). Three rows out of eight, and A = 0 can never sound the alarm.
- The circuit is one OR gate on B and C feeding one AND gate with A.
例题:机器警报
- 当护罩打开(A = 1)并且电机在运行(B = 1)或温度过高(C = 1)时,警报 X 响起。
- "B 或 C"是
B OR C。"A 且 那个"是X = A AND (B OR C)。OR 外面的括号必不可少。 - X = 1 需要 A = 1 且 B、C 中至少一个为 1:行 (1, 0, 1)、(1, 1, 0) 和 (1, 1, 1)。八行中的三行,而 A = 0 永远不能触发警报。
- 电路是 B 和 C 进一个 OR 门,再与 A 一起进一个 AND 门。
For the alarm X = A AND (B OR C), the alarm can sound when A = 0 provided both B and C are 1. · 对警报 X = A AND (B OR C),只要 B 和 C 都为 1,A = 0 时警报也能响。
The AND with A means A = 1 is required in every row where X = 1. With A = 0 the output is 0 whatever B and C do. · 与 A 的 AND 意味着 X = 1 的每一行都需要 A = 1。A = 0 时,不管 B 和 C 怎样,输出都是 0。
Marks that slip away
A AND B OR Cwithout brackets is ambiguous, and the examiner reads it as you did not intend. Bracket the OR before ANDing it.- A wire that goes nowhere, or an output with no label, loses the circuit mark even when the gates are right.
- A NOT on an input is a gate on the diagram, not a bar written over the letter.
- Three inputs mean eight rows. A table with fewer rows cannot be marked as complete.
容易丢掉的分
- 没有括号的
A AND B OR C有歧义,考官会按你不想要的方式读它。先给 OR 加括号再 AND。 - 一条没有去处的线,或没有标签的输出,即使门都对也会丢掉电路分。
- 输入上的 NOT 在图上是一个门,不是写在字母上的横线。
- 三个输入意味着八行。行数不够的表不能被判为完整。
You've got it
- expression → circuit: one gate per operator, innermost brackets first, inputs left, labelled output right
- circuit → expression: label each intermediate output (P, Q) and combine; circuit → truth table: $2^{n}$ rows with a column per gate
- truth table → expression: sum of products, one AND-term per output-1 row, ORed together; XOR + AND make the half adder
- problem → Boolean: exactly one = XOR, neither = NOR, not both = NAND; bracket the OR inside an AND
你掌握了
- 表达式 → 电路:每个运算符一个门,先最里层括号,输入在左,带标签的输出在右
- 电路 → 表达式:给每个中间输出加标签(P、Q)再组合;电路 → 真值表:$2^{n}$ 行,每个门一列
- 真值表 → 表达式:积之和,每个输出为 1 的行一个 AND 项,用 OR 连起来;XOR + AND 构成半加器
- 问题 → 布尔:恰好一个 = XOR,都不 = NOR,不同时 = NAND;AND 里面的 OR 要加括号