Logic gates · 逻辑门
| English | 中文 | Pinyin · 拼音 |
|---|---|---|
| logic gate/ˈlɒdʒɪk ɡeɪt/ | 逻辑门 | luó jí mén |
| truth table/truːθ ˈteɪbl/ | 真值表 | zhēn zhí biǎo |
| Boolean/ˈbuːlɪən/ | 布尔 | bù ěr |
| logic expression/ˈlɒdʒɪk ekˈspreʃn/ | 逻辑表达式 | luó jí biǎo dá shì |
The master's thesis that built the digital world
- In 1937 a 21-year-old student, Claude Shannon, noticed that the on-off relays in telephone exchanges behaved exactly like the true-false algebra George Boole had written a century earlier.
- His thesis showed that any logical statement could be built as a circuit of switches, and any circuit of switches described as a logical statement.
- Every processor made since is a very large number of those switches, arranged into a handful of standard logic gates 逻辑门.
- This lesson is the handful: six gates, their symbols, and their truth tables.
建起数字世界的一篇硕士论文
- 1937 年,21 岁的学生 Claude Shannon 注意到,电话交换机里的开关继电器的行为,和一个世纪前 George Boole 写下的真假代数完全一样。
- 他的论文证明,任何逻辑陈述都能做成一个开关电路,任何开关电路都能描述为一个逻辑陈述。
- 从那以后制造的每一个处理器,都是数量极多的这种开关,排列成少数几种标准的逻辑门(logic gate)。
- 这一课就是这少数几种:六个门、它们的符号,以及它们的真值表。
What a logic gate is
- A logic gate is a small circuit that carries out one Boolean 布尔 operation. Every input and every output is either 0 (false, low voltage) or 1 (true, high voltage).
- For each gate you must know three things: its symbol, its function in words, and its truth table 真值表, which lists the output for every combination of inputs.
- Every gate in this course has two inputs except NOT, which has one.
The six gates: a shape for each, and a bubble where the output is inverted
什么是逻辑门
- 逻辑门是执行一个布尔(Boolean)运算的小电路。每个输入和每个输出都要么是 0(假,低电压)要么是 1(真,高电压)。
- 对每个门你必须知道三件事:它的符号、它用文字表达的功能,以及它的真值表(truth table)——列出每种输入组合对应的输出。
- 这门课里的每个门都有两个输入,除了只有一个输入的 NOT。

六个门:每个一种形状,输出取反处有一个小圆圈
Logic gates · 逻辑门
output from the truth table · 由真值表得出的输出
Toggle A and B through a gate and watch the truth table row light up. · 通过一个门切换 A 和 B,看 真值表 的行点亮。
NOT, AND, OR
- NOT inverts its single input: 0 becomes 1 and 1 becomes 0.
- AND outputs 1 only when both inputs are 1.
- OR outputs 1 when at least one input is 1, so it is 0 only when both inputs are 0.
| A | B | A AND B | A OR B |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 |
NOT、AND、OR
- NOT 把它唯一的输入取反:0 变成 1,1 变成 0。
- AND 只有当两个输入都是 1 时才输出 1。
- OR 在至少一个输入是 1 时输出 1,所以只有两个输入都是 0 时才是 0。
| A | B | A AND B | A OR B |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 |
A NOT gate outputs 1 when its input is 0. · 一个 NOT 门在它的输入是 0 时输出 1。
NOT inverts: 0 → 1 and 1 → 0. · NOT 取反:0 → 1 和 1 → 0。
An AND gate outputs 1 when: · 一个 AND 门在以下时输出 1:
AND outputs 1 only if every input is 1; otherwise 0. · AND 只在每个输入都是 1 时输出 1;否则 0。
An OR gate outputs 0 only when: · 一个 OR 门只在以下时输出 0:
OR is 1 if at least one input is 1, so it is 0 only when every input is 0. · OR 在至少一个输入是 1 时为 1,所以它只在每个输入都是 0 时为 0。
NAND, NOR, XOR
- NAND is NOT AND: the output is 0 only when both inputs are 1, and 1 otherwise.
- NOR is NOT OR: the output is 1 only when both inputs are 0.
- XOR (exclusive OR, also written EOR) outputs 1 when the inputs are different, and 0 when they are the same.
| A | B | A NAND B | A NOR B | A XOR B |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 |
NAND、NOR、XOR
- NAND 是 NOT AND:只有当两个输入都是 1 时输出为 0,否则为 1。
- NOR 是 NOT OR:只有当两个输入都是 0 时输出为 1。
- XOR(异或,也写作 EOR)在输入不同时输出 1,输入相同时输出 0。
| A | B | A NAND B | A NOR B | A XOR B |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 |
A XOR gate outputs 1 when: · 一个 XOR 门在以下时输出 1:
XOR (exclusive OR) is 1 when the inputs differ (0,1 or 1,0) and 0 when they are the same. · XOR(异或)在输入不同(0,1 或 1,0)时为 1,在它们相同时为 0。
A NAND gate outputs 0 only when: · 一个 NAND 门只在以下时输出 0:
NAND = NOT AND, so it is 0 exactly when AND would be 1 (all inputs 1), and 1 otherwise. · NAND = NOT AND,所以它恰好在 AND 会是 1 时(所有输入 1)为 0,否则为 1。
A NOR gate with both inputs 0 outputs what value (0 or 1)? · 一个两个输入都是 0 的 NOR 门输出什么值(0 或 1)?
NOR = NOT OR. OR of (0,0) is 0, so NOR is 1. NOR is 1 only when all inputs are 0. · NOR = NOT OR。(0,0)的 OR 是 0,所以 NOR 是 1。NOR 只在所有输入都是 0 时为 1。
Worked example: building a truth table
- Task: construct the truth table for a NOR gate.
- Write the input columns A and B and list every combination in binary counting order: 00, 01, 10, 11. Four rows, never three, never repeated.
- Apply the rule to each row. NOR is 1 only when both inputs are 0, so the output column reads 1, 0, 0, 0.
- The order matters for the marks: the examiner compares your output column with the scheme row by row.
例题:构造真值表
- 题目:构造 NOR 门的真值表。
- 写出输入列 A 和 B,并按二进制计数顺序列出每种组合:00、01、10、11。四行,不能是三行,也不能重复。
- 对每一行应用规则。NOR 只有在两个输入都为 0 时才是 1,所以输出列是 1、0、0、0。
- 顺序关系到分数:考官把你的输出列与评分标准逐行比较。
Put the rows of a two-input truth table in the order the examiner expects. · 把双输入真值表的各行按考官期望的顺序排列。
Binary counting order: 00, 01, 10, 11. The output column is then compared with the mark scheme row by row. · 二进制计数顺序:00、01、10、11。然后输出列与评分标准逐行比较。
Worked example: defining a gate in words
- Task: define the function of an XOR gate.
- The mark-scheme wording: the output is 1 when the inputs are different, or equivalently when exactly one input is 1; the output is 0 when both inputs are the same.
- For NAND: the output is 0 only when both inputs are 1. For NOR: the output is 1 only when both inputs are 0.
- "Only when" and "at least one" are doing the work in these sentences. Leave them out and the definition also describes another gate.
例题:用文字定义一个门
- 题目:定义 XOR 门的功能。
- 评分标准的措辞:输入不同时输出为 1,等价地说,恰好一个输入为 1 时输出为 1;两个输入相同时输出为 0。
- NAND:只有当两个输入都是 1 时输出为 0。NOR:只有当两个输入都是 0 时输出为 1。
- 这些句子里干活的是"只有当"和"至少一个"。去掉它们,这个定义就也能描述另一个门。
Reading a symbol
- AND has a flat back and a rounded front, like a D. OR has a curved back and a pointed front. XOR is OR with an extra curved line across its inputs.
- A small circle, the bubble, on the output means "invert". AND with a bubble is NAND, OR with a bubble is NOR.
- NOT is a triangle with a bubble: one input, one output.
Flat back for AND, curved back for OR, an extra line for XOR, a bubble for NOT
读懂符号
- AND 背面平、前面圆,像个 D。OR 背面弯曲、前面尖。XOR 是 OR 再在输入侧多一条弧线。
- 输出端的小圆圈——气泡——表示"取反"。带气泡的 AND 是 NAND,带气泡的 OR 是 NOR。
- NOT 是带气泡的三角形:一个输入,一个输出。

平背是 AND,弯背是 OR,多一条线是 XOR,气泡是取反
Match each description of a symbol to its gate. · 把每个符号描述与它的门配对。
The back of the shape says AND or OR; the extra line says exclusive; the bubble says inverted. · 形状的背面说明是 AND 还是 OR;多出的线说明是异或;气泡说明取反。
Recognising a gate from its output column
- Read the output column from the 00 row down to the 11 row.
- 0 0 0 1 is AND. 0 1 1 1 is OR. 0 1 1 0 is XOR.
- 1 1 1 0 is NAND. 1 0 0 0 is NOR. The inverted gates begin with a 1 where their partner begins with a 0.
从输出列认出门
- 从 00 行到 11 行读输出列。
- 0 0 0 1 是 AND。0 1 1 1 是 OR。0 1 1 0 是 XOR。
- 1 1 1 0 是 NAND。1 0 0 0 是 NOR。取反的门在它的搭档以 0 开头的地方以 1 开头。
For inputs A = 0 and B = 1, which gates output 1? Select all · 所有 that apply. · 当输入 A = 0、B = 1 时,哪些门输出 1?选出所有适用的。
One input is 1, so OR and XOR give 1; both are not 1, so AND gives 0 and NAND gives 1; both are not 0, so NOR gives 0. · 有一个输入是 1,所以 OR 和 XOR 给 1;不是两个都为 1,所以 AND 给 0、NAND 给 1;不是两个都为 0,所以 NOR 给 0。
Writing the logic expression
- A logic expression 逻辑表达式 writes the gate as words:
X = A AND B,X = A OR B,X = NOT A,X = A NAND B,X = A NOR B,X = A XOR B. - Brackets show which operation happens first when gates are joined:
X = (A AND B) OR C. - The expression, the truth table and the circuit are three views of one function. Next lesson joins the gates into circuits and moves between all three.
写出逻辑表达式
- 逻辑表达式(logic expression)用文字写出这个门:
X = A AND B、X = A OR B、X = NOT A、X = A NAND B、X = A NOR B、X = A XOR B。 - 门连接起来时,括号表示哪个运算先做:
X = (A AND B) OR C。 - 表达式、真值表和电路是同一个函数的三种视图。下一课把门连成电路,并在这三者之间转换。
A circuit outputs 1 only when both of its inputs are 1. Which logic expression describes it? · 一个电路只有当两个输入都为 1 时才输出 1。哪个逻辑表达式描述它?
"Only when both" is the AND definition. NAND is its inverse, OR needs only one input, XOR needs them to differ. · "只有当两个都"就是 AND 的定义。NAND 是它的反,OR 只需要一个输入,XOR 需要它们不同。
Marks that slip away
- XOR is not OR. For inputs 1 and 1, OR gives 1 and XOR gives 0.
- NAND is NOT (A AND B), not (NOT A) AND B. The bubble is on the output.
- Truth-table rows go 00, 01, 10, 11. A table in another order is marked as wrong even when every row is right.
- A NOT gate has one input. Every other gate in this course has exactly two.
容易丢掉的分
- XOR 不是 OR。输入为 1 和 1 时,OR 给 1,XOR 给 0。
- NAND 是 NOT (A AND B),不是 (NOT A) AND B。气泡在输出端。
- 真值表的行按 00、01、10、11。用别的顺序的表即使每行都对也算错。
- NOT 门只有一个输入。这门课里其他每个门都恰好有两个。
You've got it
- a gate does one Boolean operation on inputs of 0 and 1; know each symbol, function and truth table
- AND = both 1 · OR = at least one 1 · NOT = invert · NAND = 0 only when both 1 · NOR = 1 only when both 0 · XOR = inputs differ
- the bubble on a symbol inverts the output; truth tables run 00, 01, 10, 11
- a logic expression writes the same function in words:
X = A NAND B
你掌握了
- 门对 0 和 1 的输入做一个布尔运算;记住每个门的符号、功能和真值表
- AND = 两个都为 1 · OR = 至少一个 1 · NOT = 取反 · NAND = 只在两个都为 1 时为 0 · NOR = 只在两个都为 0 时为 1 · XOR = 输入不同
- 符号上的气泡把输出取反;真值表按 00、01、10、11
- 逻辑表达式用文字写出同一个函数:
X = A NAND B