# 1.3 布尔逻辑与逻辑电路（Boolean Logic & Logic Gates）

> 抽象（Abstraction）
>
> 在计算机科学中，抽象化是将资料与程序，以它的语义来呈现出它的外观，但是隐藏起它的实现细节。
>
> 抽象化是用来减少程序的复杂度，使得程序员可以专注在处理少数重要的部分。
>
> (cr. [wikipedia](https://zh.wikipedia.org/wiki/%E6%8A%BD%E8%B1%A1%E5%8C%96_\(%E8%A8%88%E7%AE%97%E6%A9%9F%E7%A7%91%E5%AD%B8\)), link [🆚 数学抽象](https://ray-eldath.me/programming/three-important-ideas/))

### 1.3.1 为何选择二进制

计算机从十进制的机电设备进化到了二进制（Binary）\
的电子设备，电路的开闭表示真（true）和假（false）两种状态。

尽管晶体管可以表示超过两种状态（以不同大小的电流经过），但可表示的状态越多，越容易受噪音的扰动，就越难以区分。而二进制的 1 和 0 很容易在电路中用「通」和「断」区分出来。

同时，布尔代数作为一种仅处理两种状态的数学分支，为计算机提供了完备的运算法则和方法。

### 1.3.2 布尔代数

布尔代数（Boolean Algebra）由英国数学家乔治·布尔（George Boole）发明，因出于对亚里士多德基于哲学的逻辑方法进行数学式扩展的兴趣，其用逻辑方程系统而正式地证明真理，并于 1847 年的首部著作《逻辑的数学分析》中进行了介绍。

布尔代数中使用 true 和 false 两个变量进行逻辑操作，其基本运算如下：

> 1. 布尔代数的基本运算可以很容易地用晶体管构建，将晶体管的控制线当作 input，将底部的电极线当作 output，则输入输出同步：&#x20;
>
>    <figure><img src="/files/JNU6aNo1ik3YTNY8FpdC" alt="" width="188"><figcaption></figcaption></figure>
> 2. 能控制电流的路径称为「门」（Gate）。
> 3. 电路图中的拱门表示 2 条线没有连接，仅仅只是跨越。
>
>    <figure><img src="/files/96YOmb1cCJbZlFlkpeR4" alt=""><figcaption></figcaption></figure>

### 1.3.3 NOT 非

数学符号： $\neg$

Tips：真假倒置

真值表：

|  A  |  !A |
| :-: | :-: |
|  真  |  假  |
|  假  |  真  |

晶体管电路：

* 上方的电极线当作 output，下方电极线接地。
* 半导体通电 True （Input on），则线路接地，无输出电流，为 False。
* 半导体不通电 False （Input off），则输出电流从上方输出，为 True。

<figure><img src="/files/msmnoAnA6qowXLeiaB78" alt=""><figcaption></figcaption></figure>

### 1.3.4 AND 与

数学符号：$\land$

Tips：一假则假，两真为真。

真值表：

|  A  |  B  | A && B |
| :-: | :-: | :----: |
|  真  |  真  |    真   |
|  真  |  假  |    假   |
|  假  |  真  |    假   |
|  假  |  假  |    假   |

晶体管电路：

* 两晶体管串联，当且仅当 2 个晶体管都通电，输出才有电流（True）。

<figure><img src="/files/rCiqZWdQdTZJeNaLFetV" alt=""><figcaption><p>1&#x26;&#x26;1->1</p></figcaption></figure>

### 1.3.5 OR 或

数学符号：$\lor$

Tips：一真为真，两假则假。

真值表：

|  A  |  B  | A \|\| B |
| :-: | :-: | :------: |
|  真  |  真  |     真    |
|  真  |  假  |     真    |
|  假  |  真  |     真    |
|  假  |  假  |     假    |

晶体管电路：

* 两晶体管并联，均无电流时晶体管阻塞，输出无电流为 False。

<figure><img src="/files/9vVlSswjTvz4VZkFFpDh" alt=""><figcaption><p>0||0->0</p></figcaption></figure>

### 1.3.6 XOR 异或

数学符号：$\oplus$

Tips：不同为真，相同则假。

真值表：

|  A  |  B  | A XOR B |
| :-: | :-: | :-----: |
|  假  |  假  |    假    |
|  假  |  真  |    真    |
|  真  |  假  |    真    |
|  真  |  真  |    假    |

晶体管电路：

<figure><img src="/files/RkSAi221Z0EKbX9fqX07" alt=""><figcaption><p>0 XOR 1->1</p></figcaption></figure>

### 1.3.7 逻辑门电路

作为用晶体管搭建的复杂电路的抽象，将逻辑门电路简化，用于构建更大的组件，而不至于太复杂。与、或、非以及异或门电路符号如下：

<figure><img src="/files/KJjEtHhLHChijR9ciElp" alt=""><figcaption><p>逻辑门电路符号</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cccs.viyi.cc/1-ji-suan-ji-zu-cheng/1.3-bu-er-luo-ji-yu-luo-ji-dian-lu-boolean-logic-logic-gates.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
