Introduction to Logic Gates
By Gabriel Torres on October 21, 2005


Introduction

Logic gates are the basic components in digital electronics. They are used to create digital circuits and even complex integrated circuits. For example, complex integrated circuits may bring already a complete circuit ready to be used – microprocessors and microcontrollers are the best example – but inside them they were projected using several logic gates. In this tutorial we will teach you everything you need to know about logic gates, with several examples.

As you may already know, digital electronics accept only two numbers, “0” and “1.” Zero means a 0 V voltage, while “1” means 5 V voltage or 3.3 V voltage on newer integrated circuits. You can think “0” and “1” as a light bulb turned off or on or as a switch turned off or on.

A letter, also known as variable, represents a binary number. So “A” can be “0” or “1.” So, if A is connected to a switch, A will be “0” when the switch is turned off and “1” when the switch is turned on. A line drawn right above the variable name means that the variable is inverted. For example, if A = 0, /A will be “1,” and if A = 1, /A will be “0.” On text processors we need to substitute the line drawn above the letter with a slash because it is hard to draw a line above the letter. So here will be using this kind of notation due to a limitation on our text processor.

Now that you know the basics, we can introduce you to logic gates.

Inverter

As the name implies, inverter will invert the number entered. If you enter “0”, you will get a “1” on its output, and if you enter a “1”, you will get a “0” on its output. The inverter symbol you can see in Figure 1. Inverter gate is also known as NOT and its output is Y = /A.

Inverter Gate
Figure 1: Inverter.

On the truth table below you can see a summary of how this circuit works.

A (Input) 

Y (Output)

0

1

1

0


On logic circuits, a “o” symbol is a short for inverter. You will see that on logic gates like NAND, NOR and XNOR.

The most famous inverter integrated circuit is 7404 and you see its pinout in Figure 2. It has six inverters inside. To make this integrated circuit work, you need to connect it to a 5 V power supply.

7404 IC
click to enlarge
Figure 2: 7404 integrated circuit provides six inverters.

AND

As its name implies, an AND logic gate performs an “AND” logic operation, which is a multiplication. It has at least two inputs. So, if A and B are its inputs, at the output we will find A x B (also represented as A · B). So, AND logic gate can be summarized by the formula Y = A x B (or Y = A · B). You can see its symbol in Figure 3 and its truth table right below it.

AND gate
Figure 3: AND logic gate.

A

B

Y

0

0

0

0

1

0

1

0

0

1

1

1

Another way to understand AND logic gate: its output will only be at “1” when all its inputs are also at “1”. Otherwise its output will be “0”.

If you are projecting a circuit and need an AND logic gate with more inputs, you can go ahead and simple draw an AND logic gate like the one in Figure 3 and put more inputs on it. But if you are working with integrated circuits with AND logic gates with fewer inputs that you need, you can expand the number of inputs by connecting them like shown in Figure 4.

AND gate
Figure 4: Expanding AND inputs using 2-input gates.

The most famous AND gate integrated circuit is 7408 and you can its pinout in Figure 5. Of course there are several other integrated circuits that provide AND gates with more inputs. For example, 7411 provides three three-input AND gates.

7408 IC
click to enlarge
Figure 5: 7408 integrated circuit provides four two-inputs AND gates.

NAND

The “N” letter on NAND stands for NOT, meaning that NAND logic gate is an AND gate with an inverter attached. So, its output is the opposite from AND. Its symbol is the same of AND but with a “o” on its output, meaning that the output is inverted. You can build yourself a NAND gate by connecting an AND gate to an inverter.

NAND gate
Figure 6: NAND logic gate.

A

B

Y

0

0

1

0

1

1

1

0

1

1

1

0

Another way to understand NAND logic gate: its output will only be at “0” when all its inputs are also at “1”. Otherwise its output will be “1”.

If you need more inputs, just draw them on the symbol shown in Figure 6. However, if you want to create more inputs using gates with fewer inputs, you cannot connect them using the same idea shown in Figure 4. You need to use AND gates for the “extra” inputs (you can link them together to expand the number of inputs like shown in Figure 4) and a NAND gate for the “final” gate, see Figure 7.

NAND gate
Figure 7: How to expand the number of inputs of a NAND gate.

You can also easily transform NAND and NOR gates into inverters by shorting their inputs, like shown in Figure 8. This is a very common trick. For example, you need an inverter in your circuit and have some NAND gates available at a given integrated circuit. Instead of adding another integrated circuit to your project just to have one inverter (what would increase the final circuit size and also the cost), you may want to use one of the available NAND gates.

NAND gate
Figure 8: Transforming a NAND gate into an inverter.

The most famous NAND gate integrated circuit is 7400 and you can its pinout in Figure 9. Of course there are several other integrated circuits that provide NAND gates with more inputs. For example, 7411 provides three three-input NAND gates and 7430 provides one eight-input NAND gate.

7400 IC
click to enlarge
Figure 9: 7400 integrated circuit provides four two-inputs NAND gates.

OR

As its name implies, an OR logic gate performs an “OR” logic operation, which is an addition. It has at least two inputs. So, if A and B are its inputs, at the output we will find A + B. So, OR logic gate can be summarized by the formula Y = A + B. You can see its symbol in Figure 10 and its truth table right below it.

OR gate
Figure 10: OR logic gate.

A

B

Y

0

0

0

0

1

1

1

0

1

1

1

1

Another way to understand OR logic gate: its output will only be at “0” when all its inputs are also at “0”. Otherwise its output will be “1”.

If you need more than two inputs, the same idea applies. If you are projecting a circuit and need an OR logic gate with more inputs, you can go ahead and simple draw an OR logic gate like the one in Figure 10 and put more inputs on it. But if you are working with integrated circuits with OR logic gates with fewer inputs that you need, you can expand the number of inputs by connecting them like shown in Figure 11.

OR gate
Figure 11: Expanding OR inputs using 2-input gates.

The most famous OR gate integrated circuit is 7432 and you can its pinout in Figure 12. Of course there are several other integrated circuits that provide OR gates with more inputs. For example, 7427 provides three three-input OR gates.

7432 IC
click to enlarge
Figure 12: 7432 integrated circuit provides four two-inputs OR gates.

NOR

The “N” letter on NOR stands for NOT, meaning that NOR logic gate is an OR gate with an inverter attached. So, its output is the opposite from OR. Its symbol is the same of OR but with a “o” on its output, meaning that the output is inverted. You can build yourself a NOR gate by connecting an OR gate to an inverter.

NOR gate
Figure 13: NOR logic gate.

A

B

Y

0

0

1

0

1

0

1

0

0

1

1

0

Another way to understand NOR logic gate: its output will only be at “1” when all its inputs are at “0”. Otherwise its output will be “0”.

If you need more inputs, just draw them on the symbol shown in Figure 13. However, if you want to create more inputs using gates with fewer inputs, you cannot connect them using the same idea shown in Figure 11. You need to use OR gates for the “extra” inputs (you can put them together to expand the number of inputs like shown in Figure 11) and a NOR gate for the “final” gate, see Figure 14.

NOR gate
Figure 14: How to expand the number of inputs of a NOR gate.

You can also easily transform NAND and NOR gates into an inverter by shorting their inputs, like shown in Figure 15. This is a very common trick. For example, you need an inverter in your circuit and have some NOR or NAND gates available at a given integrated circuit. Instead of adding another integrated circuit to your project just to have one inverter (what would increase the final circuit size and also the cost), you may want to use one of the available NAND or NOR gates.

NOR gate
Figure 15: Transforming a NOR gate into an inverter.

The most famous NOR gate integrated circuit is 7402 and you can its pinout in Figure 16. Pay attention because the location of the inputs and outputs on this integrated circuit is different from the other integrated circuits we’ve seen before. Of course there are several other integrated circuits that provide NOR gates with more inputs. For example, 7427 provides three three-input NOR gates.

7402 IC
click to enlarge
Figure 16: 7402 integrated circuit provides four two-inputs NOR gates.

XOR

XOR stands for exclusive OR. XOR gates count the number of “1s” available at their inputs and if it is an even number, the output will be “0,” and if it is an odd number, the output will be “1.” (Don’t forget that zero is an even number, so when all inputs are “0”, the output will be “0”.) XOR operation is represented by the symbol ⊕. So Y = A ⊕ B. You can see XOR logic gate symbol in Figure 10 and its truth table right below it.

XOR gate
Figure 17: XOR logic gate.

A

B

Y

0

0

0

0

1

1

1

0

1

1

1

0

If you need more than two inputs, you will need to add another XOR gate as shown in Figure 18.

Expanding XOR logic gates
Figure 18: Expanding XOR inputs.

The most famous XOR gate integrated circuit is the 7486 and you can its pinout in Figure 19.

7486 IC
click to enlarge
Figure 19: 7486 integrated circuit provides four two-input XOR gates.

XNOR

XNOR stands for exclusive NOR and is an XOR gate with its output inverted. So, its output is at “1” when the inputs have the same value and “0” when they are different. XNOR operation is represented by the symbol (·). So Y = A (·) B. You can see XNOR logic gate symbol in Figure 20 and its truth table right below it.

XNOR gate
Figure 20: XNOR logic gate.

A

B

Y

0

0

1

0

1

0

1

0

0

1

1

1

So its output will only be at “1” when all its inputs have the same value. Otherwise its output will be “0”.

If you need more than two inputs, you will need to add an AND gate like shown in Figure 21. Another way is to use the circuit shown in Figure 18 adding an inverter on its output.

XNOR gate
Figure 21: Expanding XNOR inputs.

As an example of integrated circuit with XNOR gates we have 747266 and you can check its pinout in Figure 22.

747266 IC
click to enlarge
Figure 22: 747266 integrated circuit provides four two-inputs XNOR gates.

Non-Inverter or Buffer

At a non-inverter, also known as buffer, the value entered on its input will be found on its output. You may think that this is a crazy logic gate, since it does nothing. That’s not true, it has several important applications on digital electronics, as we will explain below.

Buffer
Figure 23: Non-inverter or buffer.

A

Y

0

0

1

1

A typical application for a buffer is to increase the fan-out of a given logic gate. Fan-out is the maximum number of gates a given integrated circuit is capable of being connected to. For example, if a given logic gate has a fan-out of 3 gates, its output can be only connected directly to three other logic gates. If you need to connect its output to more logic gates, you can use a buffer to increase the number of logic gates you can connect this output to.

Another application for the buffer is the use of a circuit where the buffer is controlled by a gate (74367 integrated circuit is a good example). In this application this logic gate will work like a gate: it will only replicate what is on its input when its gate pin is activated.

74367 IC
click to enlarge
Figure 24: 74367 integrated circuit pinout.

One more application for a Non-Inverter is to create a delay line. Since each integrated circuit delays a little bit to replicate what is on its input on its output, a non-inverter can be used to delay the signal. This idea is used on some digital oscillator circuits, for example. If you take the circuit in Figure 25, if each gate delays the signal 10 ns (nanoseconds), with four gates we will have a 40 ns delay line.

Delay Line
click to enlarge
Figure 25: A delay line.

Another very common application for both non-inverters and inverters is to drive circuits that need more current or need to work with voltages different from 5 V as “1”. This topic is really important and we will be explaining that in the next page.

Open Collector and Open Drain

As we said before, “1” means 5 V. Sometimes you need a higher voltage for controlling a device that doesn’t work with 5 V. You may want to control a 12 V relay, for example. Also, sometimes you may want to control a 5 V circuit but it drives more current than a standard integrated circuit can deliver. In those cases, you can use open-collector configuration.

Integrated circuits from the 74xxx series (all integrated circuit examples we are giving on this tutorial) are based on a technology called TTL, Transistor-Transistor Logic. Open collector means that the transistor used on the output of the gate doesn’t have its collector internally connected to the integrated circuit’s VCC (voltage). So, you have to do this connection by yourself. This means that you need to install an external resistor (called “pull-up”) between the output and VCC to make the circuit work. The good thing is that VCC doesn’t need to be the +5 V power supply. You can install it to a + 12 V power supply and feed your 12 V relay, for example.

The term open-drain is used for CMOS integrated circuits and is exactly the same thing.

Open collector or open drain gates are usually marked with an asterisk.

Open Collector
click to enlarge
Figure 26: Example of open collector circuit.

Open collector configuration has far more applications. The most common is a technique called wired-AND, where the junction works as an AND gate. See the example in Figure 27. The output Y will be equal to (A OR B) AND (C NAND D). The junction will work as an AND gate.

Open Collector
click to enlarge
Figure 27: Example of wired-AND using open collector logic gates.

Some open collector integrated circuits include 7403 (NAND gates, same pinout as 7400), 7405 (inverters, same pinout as 7404), 7409 (AND gates, same pinout as 7408) and 7433 (NOR gates, same pinout as 7402), just to mention a few examples.

We will stop here otherwise we will be leaving the original subject of this tutorial.

Originally at http://www.hardwaresecrets.com/article/Introduction-to-Logic-Gates/237


© 2004-14, Hardware Secrets, LLC. All Rights Reserved.

Total or partial reproduction of the contents of this site, as well as that of the texts available for downloading, be this in the electronic media, in print, or any other form of distribution, is expressly forbidden. Those who do not comply with these copyright laws will be indicted and punished according to the International Copyrights Law.

We do not take responsibility for material damage of any kind caused by the use of information contained in Hardware Secrets.