# 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.


---

# 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://cs.brash.ca/unit-1/binary-and-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.
