> For the complete documentation index, see [llms.txt](https://cs.brash.ca/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cs.brash.ca/unit-1/binary-and-logic/logic-gates.md).

# Logic Gates

Controlling electricity gives us the ability to make yes and no decisions or **`true`** and **`false`**. By combining two signals, we can give a single **`true`** or **`false`** answer, depending on the **`logic`**. The flow of electricity is controlled using **`gates`** (no, not named after Bill Gates - like a [gate](https://cdn.instructables.com/FT3/MIN3/IEOP6MV9/FT3MIN3IEOP6MV9.LARGE.jpg?auto=webp)).

![Standard Logic Gate Symbols](/files/-LM_Ikq6BsdciPsTVHwI)

{% tabs %}
{% tab title="NOT" %}
The simplest gate, this item **`inverts`** or reverses the signal.   $$Q= \overline A$$&#x20;

<div align="left"><img src="/files/-LM_JipKiK0Mf1KNkKp_" alt=""></div>

| Input (A) | Output (Q) |
| --------- | ---------- |
| 0         | 1          |
| 1         | 0          |

{% endtab %}

{% tab title="AND" %}
Only outputs true if both inputs are true.  $$Q = A \cdot B \text{ or } A \times B$$&#x20;

<div align="left"><img src="/files/-LM_LVcZR1vFjql4t15S" alt=""></div>

| A            | B | Output (Q) |
| ------------ | - | ---------- |
| 0            | 0 | 0          |
| 0            | 1 | 0          |
| 1            | 0 | 0          |
| 1            | 1 | 1          |
| {% endtab %} |   |            |

{% tab title="NAND" %}
Any gate with a dot is an `inverted` gate.    $$Q = \overline{A \cdot B} \text{ or } \overline{A \times B}$$ \
This is the NOT AND gate: &#x20;

<div align="left"><img src="/files/-LM_O2ZnU8dojgpzefhp" alt=""></div>

| A            | B | Output (Q) |
| ------------ | - | ---------- |
| 0            | 0 | 1          |
| 0            | 1 | 1          |
| 1            | 0 | 1          |
| 1            | 1 | 0          |
| {% endtab %} |   |            |

{% tab title="OR" %}
One or the other or both!    $$Q = A+B$$&#x20;

<div align="left"><img src="/files/-LM_PcsCsnxBDXy5eCLs" alt=""></div>

| A            | B | Output (Q) |
| ------------ | - | ---------- |
| 0            | 0 | 0          |
| 0            | 1 | 1          |
| 1            | 0 | 1          |
| 1            | 1 | 1          |
| {% endtab %} |   |            |

{% tab title="NOR" %}
Very simply NOT OR.    $$Q = \overline{A+B}$$&#x20;

<div align="left"><img src="/files/-LM_QC-m4b-fdefeBNkH" alt=""></div>

| A            | B | Output (Q) |
| ------------ | - | ---------- |
| 0            | 0 | 1          |
| 0            | 1 | 0          |
| 1            | 0 | 0          |
| 1            | 1 | 0          |
| {% endtab %} |   |            |

{% tab title="XOR" %}
Exclusive OR meaning only one is true, not both.    $$Q = A \bigoplus B$$&#x20;

<div align="left"><img src="/files/-LM_Qvu8nyvFozH50l_k" alt=""></div>

| A            | B | Output (Q) |
| ------------ | - | ---------- |
| 0            | 0 | 0          |
| 0            | 1 | 1          |
| 1            | 0 | 1          |
| 1            | 1 | 0          |
| {% endtab %} |   |            |

{% tab title="XNOR" %}
Exclusively NOT OR. If both inputs are the same, output true.    $$Q = \overline{A \bigoplus B}$$&#x20;

<div align="left"><img src="/files/-LM_S2v8NhfdBetjBeum" alt=""></div>

| A            | B | Output (Q) |
| ------------ | - | ---------- |
| 0            | 0 | 1          |
| 0            | 1 | 0          |
| 1            | 0 | 0          |
| 1            | 1 | 1          |
| {% endtab %} |   |            |

{% tab title="All Truth Tables" %}

| A | B | AND | NAND | OR | NOR | XOR | XNOR |
| - | - | --- | ---- | -- | --- | --- | ---- |
| 0 | 1 | 0   | 1    | 0  | 1   | 0   | 1    |
| 0 | 1 | 0   | 1    | 1  | 0   | 1   | 0    |
| 1 | 0 | 0   | 1    | 1  | 0   | 1   | 0    |
| 1 | 0 | 1   | 0    | 1  | 0   | 0   | 1    |

#### Individually:

![](/files/-LMwN7aHaRL4XU9HGSU4)
{% endtab %}
{% endtabs %}

{% hint style="info" %}
The two "universal" gates are **`NOR`** and **`NAND`** - it is said that you can create all the other logic gates with a combination of just these two.
{% endhint %}

There are [tons of videos](https://www.youtube.com/results?search_query=logic+gates) available about logic gates. If I had to pick a favourite, my current is [this one](https://youtu.be/gI-qXk7XojA), although she talks incredibly fast and you might need to slow it down or rewind.
