## Digital Electronics Fundamentals 4: Universal Gates

There are certain logic basic gates that can be used to reproduce the functionality of any other gate. To do that, these gates need to be able to do inversion in addition to their basic functionality. They are the NAND gate and the NOR gate. In this article, we will examine how that can be achieved.

## NAND, NOT, AND

If we tale a look at the truth table of such gate, we find that considering only the first and the last row of it, it behaves exactly like a NOT gate.

To make it work, we just need to put together the two inputs of the gate, and it will work as an inverter.

Given that, we can easily build an AND gate out of two NAND gates. The first gate provides the NAND function and the second provides a NOT function that converts the NAND into an AND.

At this point, before showing how to create any other gate from the NAND gate, we have to enounce the De Morgan theorem, which will allow us to manipulate the boolean expressions of the various gates to convert them into a number of NAND gates connected together.

## De Morgan Theorem

The theorem states that we can convert a NAND operation into an OR operation, and we can also convert a NOR operation in to an AND operation, according to certain rules. Here is the theorem expressed in boolean algebra:

If you like to verify that the theorem holds true, just build the truth table for the right side of each equation and compare it with the truth table of the corresponding left side, which are respectively a NOR and a NAND truth table. The tables on the two sides should be identical.

## OR from NAND

Let’s see now how we can make an OR gate using a circuit with only NAND gates.

Here is the symbol of the OR gate:

And here is its truth table:

Let’s now write down the boolean expression for the OR gate and let’s apply to it the De Morgan theorem so we can convert everything to AND and NAND.

The one on the right is the boolean expression of the OR gate expressed in terms of NAND gates, and we can convert it in to a digital circuit like this:

Again, to prove that this circuit really behaves like an OR gate, we can deduct its truth table and compare it with the one of the actual OR gate. If they are identical, this circuit effectively mimics the OR gate. try yourself and, if you have difficulties, please take a look at the companion video on YouTube. The link is at the end of this post.

## NOR from NAND

Like we did for the OR gate, we could determine the boolean expression of the NOR gate and find how to build the circuit that mimics it. However, since the NOR gate is essentially the same as the series of the OR gate and the NOT gate, we cna just reuse the previous circuit and add the NOT at its output, as in the following picture:

You can demonstrate the correctness of this circuit by comparing again, its truth table with the one of the NOR gate.

## XOR from NAND

To convert the XOR gate in to a combination of NAND gates, we need to start from its truth table:

Now we can write down the boolean expression of the XOR gate by referencing to the lines of the truth table that have an output of one, like we have seen in the previous episode. One we have the XOR boolean expression, we can manipulate it using De Morgan to obtain a form that can be described with NAND gates only:

And, finally, we can draw the digital circuit corresponding to the rightmost part of the above boolean expression:

And this is the circuit that mimics the XOR gate using only NAND gates. And guess how we can prove that?

## XNOR from NAND

For the XNOR gate, we could just add a NOT at the output of the previous circuit. However, we can use one less NAND gate if we redo the whole procedure we made for the XOR gate.

Here is its truth table:

Here is the derived boolean expression appropriately manipulated:

And here is the corresponding schematic made only of NAND gates:

## NOR, NOT, OR

Let’s now talk about the other universal gate: the NOR gate.

Here is its truth table:

And we can see from there that connecting together the two inputs we obtain, like with the NAND gate, a NOT function.

Given those two ports, it is easy to implement the OR gate:

Do you see the similarity with what we have done with the NAND gate? At this point we can easily proceed with generating all the other basic ports using a similar procedure, with the only difference that we will now use the second part of the De Morgan theorem, rather than the first.

## XOR from NOR

Here is the XOR truth table:

Let’s now derive the boolean expression from this truth table. This time, however, it is more convenient to work with the zeros of the table, for which we will use OR operations, and the OR operations will be ANDed to each other and the whole expression is manipulated to obtain all NOR gates, like this:

## XNOR from NOR

Similarly, from the XNOR truth table we have:

## Conclusion

I would finally like to remind you that this series of tutorials is also backed by a corresponding video series available on YouTube. The following page provides the links to the YouTube Videos, as well as the link for the whole series, and the links to all the files involved in the tutorials, with schematics and anything else that might be needed:

## Digital Electronics Fundamentals 3: XOR and XNOR gates

After going through some basics in the previous episode, today we will look at a couple of more gates and, with that excuse, we will see how to use truth tables and some simple Boolean algebra to design a logic circuit.

## The XOR Gate

Let’s begin by talking about the XOR gate.

Here is its truth table, which describes how this gate works:

You can see how whenever the two inputs are different, the output is a 1, and it is a 0 when the inputs are different.

We could say that this kind of gate tells us if a number of digital signals are all the same or are different.

The XOR port is available in integrated circuits that contain a number of them, like this one in the picture. And from the picture you can also read the full name of the gate: the Exclusive OR. Another way to say that the circuit provides at its output an OR operation, but exclusively if the inputs are different. Like they say, if one or the other is at 1, but not both.

Let’s see now how we can draw the schematic of such circuit starting from the truth table. There are two methods to use. The first one is to look at all the rows that have a 1 at the output. We will look at the other method in a later episode.

So, here are the two rows that have ones on the output:

Let’s look now at the corresponding inputs. For each of these two rows, we write the name of the input as is, if it is represented by a 1, and as a NOT input if it is represented by a 0.

For the first of the two rows, we therefore write

And yes, we consider this as an AND operation, so we write down the two inputs as if they were multiplied by each other.

Now we are going to add to this expression the one for the other row that has an output of 1. Keep in mind that when we say “add” in boolean algebra, we intend the OR operation.

Following the same rule we used for the first raw, we then write:

The result of this whole operation is our output U:

We have now a Boolean expression that can be easily translated to a schematic, if we just keep in mind what each of the symbols represents.

And this is the schematic of the XOR gate, made with 2 AND gates, 2 NOT gates, and 1 OR gate.

We can quickly double check if this circuit works really as described by the truth table.

Consider first the rows with an output of 1. In them, A and B are opposite. And now look at the circuit. Because in each AND we get both A and the opposite of B, we can be sure that we are inputting two identical values, either both zeros or both ones, on each of the two ports. And while we are inputting both 0s on one port, the other port gets both 1s, and vice-versa. The result is that one AND gate will have an output of 1 and the other will have an output of 0. And since these outputs go to the OR gate, the output of the OR gate will be 1 in both cases.

If we look now at the rows of the truth table where the output is 0, you’ll see that the inputs are either both at 1 or both at 0. Back to the schematic, if A and B are both 1 or both zero, each of the AND gates will have at their input a 1 and a 0, because of the presence of the NOTs. Therefore, the two AND gates will both have, simultaneously, an output of 0. And since these are the inputs of the OR, the output of the OR will be 0 in both cases.

## The XNOR Gate

Let’s now work on the XNOR gate.

Here is it’s truth table:

since this is a NOT XOR, the outputs are exactly the inverse of the XOR gate.

As such, when we refer to the symbol for the XNOR gate, we just draw the one for the XOR gate and then we put a NOT at its output.

Like with the XOR gates, we have ICs that can provide multiple XNOR gates, like this one in the picture, which provides 4 gates with 2 inputs each:

Let’s now repeat the previous exercise to draw the schematic for this gate. These are the rows that present a 1 at their output.

For the first row, since both A and B are at zero, we have to write NOT A and NOT B. Then we write the OR symbol, and then we add the part relative to the second row with an output of 1. In this case, both the inputs are at 1, and so we simply write down the names of the inputs. This boolean expression now represents the truth table for the XNOR, so we put it equal to U.

And here is the corresponding schematic:

We can verify that this circuit satisfies the truth table, by noticing that while one of the two AND gates takes A and B, the other one takes NOT A and NOT B. As a result, only if A and B are exactly the same, one of the two AND gates will output a 1. Otherwise, if A and B are different, the AND gates will always have a 0 and a 1 as inputs, which will cause them to output a 0. And so, in the case A and B are the same, the OR gate will receive a 0 and a 1 at the inputs, therefore giving an output of 1. Instead, in the case where A and B are different, the OR gate will receive 0 on both inputs, therefore giving a 0.

## Conclusion

Whenever you have a truth table that describes a certain logic function, is always possible to write the Boolean expression equivalent to the truth table, and from that, we can finally draw the schematic for such function.

Note also that if we have a truth table with more than 2 inputs, we can still go through the exact same procedure, just keep in mind that we will need gates with more than 2 inputs.

And finally, I would also like to remind you that this series of tutorials is also backed by a corresponding video series available on YouTube. The following page provides the links to the YouTube Videos, as well as the link for the whole series, and the links to all the files involved in the tutorials, with schematics and anything else that might be needed: