## Flip Flops

One of the more interesting things that you can do with Boolean gates is to create **memory** with them. If you arrange the gates correctly, they will remember an input value. This simple concept is the basis of RAM (random access memory) in computers, and also makes it possible to create a wide variety of other useful circuits.

Memory relies on a concept called **feedback**. That is, the output of a gate is fed back into the input. The simplest possible feedback circuit using two inverters is shown above.

If you follow the feedback path, you can see that if Q happens to be 1, it will always be 1. If it happens to be 0, it will always be 0. Since it's nice to be able to control the circuits we create, this one doesn't have much use -- but it does let you see how feedback works.

It turns out that in "real" circuits, you can actually use this sort of simple inverter feedback approach. A more useful **feedback circuit using two NAND gates is shown below:**

This circuit has two inputs (**R** and **S**) and two outputs (**Q** and **Q'**). Because of the feedback, its logic table is a little unusual compared to the ones we have seen previously:

### R S Q Q'

0 0 Illegal

0 1 1 0

1 0 0 1

1 1 Remembers

What the logic table shows is that:

- If R and S are opposites of one another, then Q follows S and Q' is the inverse of Q.
- If both R and S are switched to 1 simultaneously, then the circuit
**remembers**what was previously presented on R and S.

There is also the funny **illegal** state. In this state, R and S both go to 0, which has no value in the memory sense. Because of the illegal state, you normally add a little **conditioning logic** on the input side to prevent it, a**s shown here:**

In this circuit, there are two inputs (D and E). You can think of **D** as "Data" and **E** as "Enable." If E is 1, then Q will follow D. If E changes to 0, however, Q will remember whatever was last seen on D. A circuit that behaves in this way is generally referred to as a **flip-flop**.

In the next section we'll look at the J-K flip-flop.