I learned very early the difference between knowing the name of something and knowing something.

-- Richard Feynman

Gates and Latches

From semiconducting material we have built the Transistor, which is the building block of modern electronics. An electrically controlled switch. It is one of the greatest inventions of mankind, right there with language, and the neural network model of the brain, fire and sliced bread.

It has 3 legs, their names are somewhat weird: Collector, Base, Emitter, but don't worry about the names, the point is, when we apply current through the base (the middle leg), electricity can flow from the collector to the emitter. It is a switch that we can control with electricity.

We can make transistors that are just 10 nanometers in size and connect billions of them into circuits that we use to compute or store information. There is research in Berkeley that actually created a working 1 nanometer transistor, the Oxygen atom is "about" 0.14 nanometers (the quotes around about are due to the absurdity of quantum mechanics, and the experimental fact that atoms do not actually have "size").

A very useful circuit with switches is the NAND gate:

S1 and S2 are switches that we control with our input X and Y, R is a resistor, and we are interested in the output at point Q.

You can see that when both S1 and S2 are open, meaning X and Y are 0, then on Q we have 1, when you close S1 or S2, again + is not connected to ground, so at Q we have 1, but when we connect both S1 and S2 then there is a path from + to - and we have no voltage at Q, so it reads 0.

Where 1 means that current goes through and 0 means it doesn't.

We can put this statement in a table:

| X | Y | Q = NAND(X,Y) |
|---|---|---------------|
| 0 | 0 | 1             |
| 0 | 1 | 1             |
| 1 | 0 | 1             |
| 1 | 1 | 0             |

This table is called "truth table". so Q is NAND(X,Y). NAND means NOT AND, in contrast with the AND truth table, where we get 1 only if both inputs are 1, :

| X | Y | Q = AND(X,Y) |
|---|---|--------------|
| 0 | 0 | 0            |
| 0 | 1 | 0            |
| 1 | 0 | 0            |
| 1 | 1 | 1            |

This is the OR table, where the output is 1 when either of the inputs is 1:

| X | Y | Q = OR(X,Y) |
|---|---|-------------|
| 0 | 0 | 0           |
| 0 | 1 | 1           |
| 1 | 0 | 1           |
| 1 | 1 | 1           |

This is the NOR table, where the output is 1 only when both inputs are 0:

| X | Y | Q = NOR(X,Y) |
|---|---|--------------|
| 0 | 0 | 1            |
| 0 | 1 | 0            |
| 1 | 0 | 0            |
| 1 | 1 | 0            |

XOR means eXclusive OR, and the output is 1 when the inputs are different:

| X | Y | Q = XOR(X,Y) |
|---|---|--------------|
| 0 | 0 | 0            |
| 0 | 1 | 1            |
| 1 | 0 | 1            |
| 1 | 1 | 0            |

We can construct all the other truth tables by various combinations of NAND gates, for example

AND(X,Y) = NAND(NAND(X,Y),NAND(X,Y))

or we can write it as

AND(X,Y) = NAND(A,A) where A is NAND(X,Y)

Lets test this, just think it through.

| X | Y | Q | Q = NAND(NAND(X,Y),NAND(X,Y))          |
|---|---|---|----------------------------------------|
| 0 | 0 | 0 | A = NAND(0,0) is 1, NAND(A=1,A=1) is 0 |
| 0 | 1 | 0 | A = NAND(0,1) is 1, NAND(A=1,A=1) is 0 |
| 1 | 0 | 0 | A = NAND(1,0) is 1, NAND(A=1,A=1) is 0 |
| 1 | 1 | 1 | A = NAND(0,0) is 0, NAND(A=0,A=0) is 1 |

So you can see we made AND truth table by using NAND.

Those gates are the very core of our digital computers. Note, you dont need electricity to create gates, there are there are gates that appear naturally from the laws of physics, People make gates from falling dominos, of from dripping water.

You can get more information from wikipedia or various pages on the internet, if you search for NAND gates. You can of course make a NAND gate with Redstone in Minecraft, and thats how people build digital computers within Minecraft.

  • https://en.wikipedia.org/wiki/Transistor
  • https://en.wikipedia.org/wiki/NAND_gate
  • https://en.wikipedia.org/wiki/NAND_logic
  • https://minecraft.fandom.com/wiki/Redstone_circuits/Logic
  • https://www.gsnetwork.com/nand-gate/

Now we get into the real meaty part, actually storing 1 bit of information in a circuit!

This circuit is called an SR Latch, for Set-Reset Latch.

The big round things in the middle are NAND gates, Q is the output and Q the inverted output (when Q is 1, Q is 0), we wont care for it, but its in the diagram for completeness. The bar on top of the letter means 'inverted'.

S is again, the inverse of S, and R is the inverse of R.

This feedback loop, where BQ feeds into A and AQ feeds into B creates a circuit that can remember.

(showing the NAND truth table again so we can reference it)

| X | Y | Q = NAND(X,Y) |
|---|---|---------------|
| 0 | 0 | 1             |
| 0 | 1 | 1             |
| 1 | 0 | 1             |
| 1 | 1 | 0             |

The SR Latch has 4 possible configurations, called Set Condition, Reset Condition, Hold Condition and Invalid Condition.

The Set Condition forces the latch to remember 1, Reset forces it to remember 0, and Hold makes it output whatever the previous value was.

Set Condition (S = 0, R = 1)

Gate A:
- AX = S = 0
- AY = Q (from Gate B)
- Since AX = 0, the NAND gate outputs Q = 1 regardless of AY
- AQ (Q) = 1

Gate B:
- BY = R = 1
- BX = Q = 1 (from Gate A)
- NAND(1,1) = 0
- BQ (Q) = 0

OUTPUT: Q = 1 (latch is set)

Reset Condition (S = 1, R = 0)

Gate B:
- BY = R = 0
- BX = Q (from Gate A)
- Since BY = 0, the NAND gate outputs Q = 1 regardless of BX
- BQ (Q) = 1

Gate A:
- AX = S = 1
- AY = Q = 1 (from Gate B)
- NAND(1,1) = 0
- AQ (Q) = 0

OUTPUT: Q = 0 (latch is reset)

Hold Condition (S = 1, R = 1)

Assuming previous state Q = 1, Q = 0:
- Gate A: AX = S = 1, AY = Q = 0
  - Since AY = 0, the NAND gate outputs Q = 1
  - AQ (Q) = 1
- Gate B: BX = Q = 1, BY = R = 1
  - NAND(1,1) = 0
  - BQ (Q) = 0
- OUTPUT: Q = 1 (latch holds previous state)
Alternatively, if previous state Q = 0, Q = 1:
- Gate A: AX = S = 1, AY = Q = 1
  - NAND(1,1) = 0
  - AQ (Q) = 0
- Gate B: BX = Q = 0, BY = R = 1
  - Since BX = 0, the NAND gate outputs Q = 1
  - BQ (Q) = 1
- OUTPUT: Q = 0 (latch holds previous state)

Invalid Condition (S = 0, R = 0)

This forces both Q and Q to be 1, which is invalid, as Q has to be the inverse of Q.

In the Hold Condition the outputs of the gates depend on their own previous outputs, creating a stable loop.

The latch remembers! The bit is stored in the infinite loop.

The SR latch is extremely fundamental building block for memory, it shows how we can store a bit of information indefinitely as long as there is power.

Another fundamental building block is the Data Flip-Flop (D Flip-Flop) circuit, which reads the Data at a clock pulse and remember is. They allow for creation of registers, counters, shift registers and memory elements.

They are more complicated, but basically it allows you to remember the Data value (0 or 1), when the Clock signal is rising. It is called an edge triggered D flip flop. But you can notice the 'latches' inside, those infinite feedback loops are what makes the circuit remember.

I won't go into more detail, but this is by no means an introduction to electronics, nor gates, nor latches, as a lot more goes into it, in practical and theoretical aspects, but it is enough for you to ask questions and have some sort of a mental model about what a 'bit' means in the computer.

If you want to investigate the subject further I suggest: