# Fundamentals of logic gates

Seth Price | November 22, 2022Computers, for all their help to the human race, can really only handle Boolean operations: true or false. In their hardware, “true” signals turn a transistor “on,” and “false” signals turn a transistor to “off.” Another way to think of this is that each transistor, or each bit, has only two possible states: 1 or 0, representing true or false. In fact, the power button on most electronic devices is simply a 1 and a 0 merged together by a graphic designer.

## What is Boolean Logic?

In order to make a computer do anything useful, such as math, graphics, control operations or surf the net, multiple bits must be combined, and decisions must be made based on the status of all of these bits. Enter Boolean Logic, where logical statements are applied to inputs to control an output.

## Truth tables

A truth table is a way to organize and predict the output of a Boolean Logic circuit for all possible input states. To set up a truth table, first evaluate how many inputs are available. The possible number of input states is:

where n is the number of input bits. For example, a 4-bit system would have 16 possible input combinations (states), where each bit could be a 1 or 0.

Once the number of states is known, build a table where each row is a possible input. To do this, count in binary from zero to the one less than the number of states. For example, in the 4-bit system, the table would start with 0000 (0) up to 1111 (15). Each of these inputs will have an output that corresponds to an output.

## Logic gates

Logic gates are methods to force an output based on inputs. They evaluate the inputs and, based on the gate, determine whether the output is true or false. There are seven basic types of logic gates, and for the purposes of this discussion, only one or two inputs and one output are required for each gate. In reality, sequences of these gates can be combined to create other gates, as NAND and NOT gates are very common in semiconductor chips, based on the device physics. Thoughtful planning can use these two gates to create some of the other types.

## Not gate

A NOT gate, sometimes called an INVERT, simply swaps an input’s state. In other words, if it is fed a true signal, it will output a false signal and vice-versa. Because they only have one input, their truth table is very simple:

## OR gate

An OR gate looks at two inputs. If either input signal is true, the output is true. Consider a piece of equipment with multiple “emergency stop” buttons; it doesn’t matter which one is pressed, and only one needs to be pressed to stop the device. These buttons can be strung together as a cascade of OR gates.

## AND gate

Even though common language uses AND and OR interchangeably, they are not interchangeable. An AND gate’s output is true if and only if all inputs are true. Think back to every B nuclear war movie where two people have to turn keys to launch the missile — this is an example of an AND gate.

## XOR gate

Now things get a little more obscure. An Exclusive-OR (XOR) gate is true if and only if one input is true. It does not matter which one, but only one is true. Suppose there is a device that has two high current heaters, but only one should run at a time. If the operator tries to turn on a second one, they both turn off.

## NOR gate

A NOR gate is simply the inverted OR gate. It can be thought of as an OR gate whose output promptly runs through a NOT gate. Consider an interlock system with two inputs that will only allow the system to start if both interlocks are closed (0), and this is an example of a NOR gate.

## NAND gate

Just as NOR is an inverted OR, NAND is an inverted AND. NAND gates are one of the more common gates in production.

## XNOR gate

The inverted XOR gate is an XNOR gate. This logic gate requires the inputs to be the same, either both false or both true to produce a true output.

## Flow charting

These logic gates can be displayed graphically using standardized symbols. In general, the input signals are on the left, and the output are on the right. Then, the chart is read from left to right, input signals through the gates to the outputs. Flow charts are useful for determining the interconnects between cascaded logic gates.

## Case example: Emergency stop routine

These gates can be cascaded such that the output from one gate becomes an input to another gate. Keeping this in mind, suppose the control logic for an emergency stop system is required for a piece of industrial equipment. The equipment has two emergency stops (ES1, ES2), an interlock (I), and a key (K). Some maintenance requires the machine to continue running, even with the interlock opened, provided the maintenance technician has inserted a key in place. The system should stop if either emergency stop button is pressed, or if the interlock is opened without the key in place.

There are four inputs and one output, where a true output shuts down the machine. The truth table per the problem statement looks like:

At first glance, this is complicated, but with some practice, this type of problem can be reasoned through. Because either emergency stop button should shut down the machine, these two inputs can be connected with an OR gate.

The interlock and key dilemma can be solved as well. The machine should stop if the interlock is opened, AND the key is NOT in place. As long as the key is in place, the machine will run; if the key is NOT in place, there is more information required. Because of this, the first step is to NOT the key input. From there, the NOT key AND the interlock will cause the machine to stop, meaning the NOT key and interlock are combined with an AND statement.

Finally, because the machine should stop whether the interlock has been activated OR the emergency stops have been activated, these two branches can be combined with an OR gate.

## Final thoughts

This is simply scratching the surface of all that is possible with logic gates. Consider that instead of one simple output means very little to the average computer user — this article, with its words and diagrams and tables is constructed entirely from these 1’s and 0’s, and complex logic circuits govern the whole process.