# 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](https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LM_DxknFF_vrZ44hlTx%2F-LM_Ikq6BsdciPsTVHwI%2FGates%20Landscape.png?alt=media\&token=e091d45a-8e48-4a2c-879b-eeeb1f70c167)

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

<div align="left"><img src="https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LM_DxknFF_vrZ44hlTx%2F-LM_JipKiK0Mf1KNkKp_%2FNOT.png?alt=media&#x26;token=742d25a0-c77f-4511-b478-0db806dcb5ef" 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="https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LM_DxknFF_vrZ44hlTx%2F-LM_LVcZR1vFjql4t15S%2FAND.png?alt=media&#x26;token=3249e15e-e5af-4155-a94b-c1bcb8862bde" 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="https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LM_Nd6VH0_Rn8uOylXm%2F-LM_O2ZnU8dojgpzefhp%2FNAND.png?alt=media&#x26;token=eb8ec3de-c5b4-43b0-a63c-e94600a86aa9" 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="https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LM_Nd6VH0_Rn8uOylXm%2F-LM_PcsCsnxBDXy5eCLs%2FOR.png?alt=media&#x26;token=364b2c7e-92e9-43fa-955e-4d3458de8f7c" 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="https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LM_Nd6VH0_Rn8uOylXm%2F-LM_QC-m4b-fdefeBNkH%2FNOR.png?alt=media&#x26;token=fb3d2c84-1d7e-4ecb-9eec-e207dc2b3348" 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="https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LM_Nd6VH0_Rn8uOylXm%2F-LM_Qvu8nyvFozH50l_k%2FXOR.png?alt=media&#x26;token=3c62e72d-87e6-4b85-b6ab-d2a40c299ed2" 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="https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LM_Nd6VH0_Rn8uOylXm%2F-LM_S2v8NhfdBetjBeum%2FXNOR.png?alt=media&#x26;token=16b8bb3f-f70b-4bcb-8e90-2ffcdda2cd81" 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:

![](https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LMwMzBalxxHZg2u4g10%2F-LMwN7aHaRL4XU9HGSU4%2FAll%20Truth%20Tables.jpg?alt=media\&token=c2371bf2-8fc9-4e0a-8edf-1003d5aa149f)
{% 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.
