📚 Logic Gates Explained: The Six Basic Gate Circuits | 逻辑门功能详解:六种基本门电路
Logic gates are the fundamental building blocks of digital circuits. They take binary inputs (0 or 1) and produce a single binary output according to a fixed logical rule. Understanding these six basic gates — NOT, AND, OR, NAND, NOR, and XOR — is essential for any computer science student.
逻辑门是数字电路的基本构件。它们接收二进制输入(0 或 1),并根据固定的逻辑规则产生单个二进制输出。理解这六种基本门电路——非门、与门、或门、与非门、或非门和异或门——对每一位计算机科学学生来说都至关重要。
1. Binary Logic and Truth Tables | 二进制逻辑与真值表
In digital electronics, a binary variable can only take one of two values: logic 0 (usually representing 0 V or low voltage) or logic 1 (usually representing a higher voltage, e.g. 5 V or 3.3 V). A truth table lists every possible combination of inputs and the corresponding output for a given gate.
在数字电子学中,二进制变量只能取两种值之一:逻辑 0(通常表示 0 V 或低电压)或逻辑 1(通常表示较高电压,如 5 V 或 3.3 V)。真值表列出了给定门电路所有可能的输入组合及对应的输出。
For a gate with n inputs, there are 2ⁿ possible input combinations. For example, a two-input gate has 4 rows in its truth table, while a three-input gate has 8 rows.
对于一个具有 n 个输入的门电路,共有 2ⁿ 种可能的输入组合。例如,双输入门电路的真值表有 4 行,而三输入门电路有 8 行。
2. NOT Gate (Inverter) | 非门(反相器)
The NOT gate has one input and one output. It simply inverts the input: if the input is 0, the output is 1; if the input is 1, the output is 0. This is why it is often called an inverter.
非门有一个输入和一个输出。它简单地将输入取反:若输入为 0,则输出为 1;若输入为 1,则输出为 0。因此它常被称为反相器。
Boolean expression: X = Ā (read as “A bar” or “NOT A”)
布尔表达式:X = Ā(读作“A 非”或“非 A”)
| Input A | Output X = Ā |
|---|---|
| 0 | 1 |
| 1 | 0 |
A common symbol is a triangle with a small circle (bubble) at the output. The bubble always indicates inversion.
常见的符号是一个三角形,输出端带一个小圆圈(气泡)。气泡始终表示取反。
3. AND Gate | 与门
The AND gate has two or more inputs. Its output is 1 only when all inputs are 1. If any input is 0, the output is 0.
与门有两个或更多输入。仅当所有输入都为 1 时,其输出才为 1。只要任一输入为 0,输出即为 0。
Boolean expression: X = A · B (often written simply as X = AB)
布尔表达式:X = A · B(通常简写为 X = AB)
| Input A | Input B | Output X |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Think of AND as a strict gatekeeper: the output is high only when every condition is satisfied. In real life, a security system with two sensors might use an AND gate so the alarm only sounds when both sensors are triggered.
可以把与门想象成严格的守门员:只有所有条件都满足时输出才为高电平。在实际生活中,带有两个传感器的安防系统可能使用与门,使得只有两个传感器都被触发时警报才响。
4. OR Gate | 或门
The OR gate has two or more inputs. Its output is 1 when at least one input is 1. The output is 0 only when all inputs are 0.
或门有两个或更多输入。当至少一个输入为 1 时,其输出为 1。仅当所有输入都为 0 时输出才为 0。
Boolean expression: X = A + B (the plus sign here means logical OR, not arithmetic addition)
布尔表达式:X = A + B(这里的加号表示逻辑或,而非算术加法)
| Input A | Input B | Output X |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
OR is inclusive: it includes the case where both inputs are 1. A simple example is a lamp that turns on if switch A OR switch B is closed (or both).
或门是包含式的:它包含两个输入都为 1 的情况。一个简单的例子是:只要开关 A 或开关 B 闭合(或两者都闭合),灯就点亮。
5. NAND Gate | 与非门
The NAND gate is the combination of an AND gate followed by a NOT gate. Its output is the exact inverse of the AND gate: it is 0 only when all inputs are 1; otherwise it is 1.
与非门是与门后接非门的组合。其输出恰为与门的反相:仅当所有输入都为 1 时输出为 0;否则输出为 1。
Boolean expression: X = A · B (with a bar over the whole expression)
布尔表达式:X = A · B 的整体取反
| Input A | Input B | Output X |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NAND gates are called “universal gates” because any other gate can be built using only NAND gates. This makes them extremely important in integrated circuit design, as manufacturers can use one standard gate type for everything.
与非门被称为“通用门”,因为仅用与非门就能搭建出任何其他门电路。这使得它们在集成电路设计中极其重要,因为制造商可以统一使用一种标准门类型来构建一切。
6. NOR Gate | 或非门
The NOR gate is the combination of an OR gate followed by a NOT gate. Its output is the exact inverse of the OR gate: it is 1 only when all inputs are 0; otherwise it is 0.
或非门是或门后接非门的组合。其输出恰为或门的反相:仅当所有输入都为 0 时输出为 1;否则输出为 0。
Boolean expression: X = A + B (with a bar over the whole expression)
布尔表达式:X = A + B 的整体取反
| Input A | Input B | Output X |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
Like NAND, NOR is also a universal gate. Any logic circuit can be constructed using only NOR gates. A NOR gate can be thought of as “not OR” — it rejects the OR behaviour entirely.
与非门一样,或非门也是通用门。任何逻辑电路都可以仅用或非门构建。可以把或非门理解为“非或”——它完全否定或门的输出行为。
7. XOR Gate | 异或门
The XOR (exclusive OR) gate has two inputs. Its output is 1 when the inputs are different, and 0 when the inputs are the same.
异或门(XOR,即“排斥或”)有两个输入。当输入不同时输出为 1;当输入相同时输出为 0。
Boolean expression: X = A ⊕ B (or A’B + AB’)
布尔表达式:X = A ⊕ B(也可写作 A’B + AB’)
| Input A | Input B | Output X |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
XOR is widely used in arithmetic circuits. For example, a half-adder uses an XOR gate to compute the sum bit of two binary digits, because binary addition produces 1 exactly when the two bits are different.
异或门广泛用于算术电路。例如,半加器使用异或门计算两个二进制位的和位,因为当两个位不同时二进制加法恰好产生 1。
8. XNOR Gate | 同或门
The XNOR (exclusive NOR) gate is the inverse of XOR. Its output is 1 when the inputs are the same, and 0 when they are different. It is also called the “equivalence gate”.
同或门(XNOR,即“排斥或非”门)是异或门的反相。当输入相同时输出为 1;当输入不同时输出为 0。它也被称为“等价门”。
Boolean expression: X = A ⊙ B (or AB + A’B’)
布尔表达式:X = A ⊙ B(也可写作 AB + A’B’)
| Input A | Input B | Output X |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
XNOR gates are used in digital comparators to check whether two binary values are equal. If the XNOR output is 1, the two bits are identical.
同或门用于数字比较器中,以检查两个二进制值是否相等。若同或门的输出为 1,则两个位完全相同。
9. Summary Table of All Six Gates | 六种门电路汇总表
The following table summarises the outputs of all six basic gates for each two-input combination. This is a handy revision tool for CIE exams.
下表汇总了六种基本门电路在每种双输入组合下的输出。这是 CIE 考试复习的实用工具。
| A | B | AND | OR | NAND | NOR | XOR | XNOR |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
Notice that NAND is the exact opposite of AND, and NOR is the exact opposite of OR. XOR and XNOR are also opposites of each other.
注意:与非门恰为与门的反相,或非门恰为或门的反相。异或门与同或门也互为反相。
10. Boolean Algebra Identities | 布尔代数恒等式
To solve logic gate problems in exams, you should remember these key identities. They help you simplify expressions and construct truth tables quickly.
要解决考试中的逻辑门题目,你应当牢记以下关键恒等式。它们有助于快速化简表达式和构建真值表。
-
X · 0 = 0 and X · 1 = X
X · 0 = 0,X · 1 = X
-
X + 0 = X and X + 1 = 1
X + 0 = X,X + 1 = 1
-
X · X = X and X + X = X
X · X = X,X + X = X
-
X · X’ = 0 and X + X’ = 1
X · X’ = 0,X + X’ = 1
-
De Morgan’s Laws: (A · B)’ = A’ + B’ and (A + B)’ = A’ · B’
德摩根定律:(A · B)’ = A’ + B’,(A + B)’ = A’ · B’
De Morgan’s laws are especially useful when converting between NAND/NOR circuits and AND/OR circuits in exam questions.
德摩根定律在考试题目中于与非门/或非门电路和与门/或门电路之间进行转换时尤其有用。
11. Building Other Gates from NAND/NOR | 用与非门/或非门构建其他门
Because NAND and NOR are universal gates, examiners often ask you to draw a circuit using only NAND gates (or only NOR gates) to achieve the same output as an AND, OR, or NOT gate.
由于与非门和或非门是通用门,考官常要求你仅用与非门(或仅用或非门)画出能够实现与门、或门或非门相同输出的电路。
Using only NAND gates:
仅用与非门实现:
-
NOT: connect both inputs of a NAND gate together. Since A NAND A = A’, this gives NOT A.
非门:将与非门的两个输入端连接在一起。因为 A 与非 A = A’,所以得到非 A。
-
AND: take a NAND gate followed by a NOT (made from another NAND). This gives (A · B)’ ‘ = A · B.
与门:先使用与非门,再用一个与非门构成非门。这样得到 (A · B)’ ‘ = A · B。
-
OR: use De Morgan’s law. A + B = (A’ · B’)’. This requires three NAND gates.
或门:运用德摩根定律。A + B = (A’ · B’)’。这需要三个与非门。
Similarly, NOR gates can build NOT, OR, and AND. Practising these constructions is a reliable way to score marks in circuit diagram questions.
类似地,或非门也可以构建非门、或门和与门。练习这些构建方法是在电路图题目中稳定得分的可靠途径。
12. Exam Tips and Common Mistakes | 考试技巧与常见错误
Here are some practical tips to avoid losing marks in CIE Computer Science logic gate questions.
以下是一些实用技巧,可帮助你在 CIE 计算机科学逻辑门题目中避免失分。
-
Always write 0 and 1, not “true” and “false”, unless the question asks for words.
始终写 0 和 1,而不是“真”和“假”,除非题目要求用文字表示。
-
Double-check the bubble: a bubble at the output of an AND gate makes it a NAND; a bubble at the output of an OR gate makes it a NOR.
仔细检查圆圈:与门输出端的圆圈使其变为与非门;或门输出端的圆圈使其变为或非门。
-
When completing a truth table, list input combinations in binary order: 00, 01, 10, 11. This reduces errors.
填写真值表时,按二进制顺序列出输入组合:00、01、10、11。这能减少错误。
-
For multi-stage circuits, work step by step. Write the output of each intermediate gate in a separate column.
对多级电路,要逐步计算。将每个中间门的输出写在单独的一列中。
-
Remember that XOR is not the same as OR. XOR output is 0 when both inputs are 1, but OR output is 1.
记住异或门不同于或门。当两个输入都为 1 时,异或门输出为 0,而或门输出为 1。
Mastering the six basic gates gives you a strong foundation for more complex topics such as flip-flops, adders, and CPU datapath design. Keep practising truth tables and boolean expressions until they become second nature.
掌握六种基本门电路,将为你学习更复杂的主题(如触发器、加法器和 CPU 数据通路设计)打下坚实基础。持续练习真值表和布尔表达式,直到它们成为你的第二本能。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导