Logic gate

A logic gate performs a logical operation on one or more logic inputs and produces a single logic output. The logic normally performed is Boolean logic and is most commonly found in digital circuits. Logic gates are primarily implemented electronically using diodes or transistors, but can also be constructed using electromagnetic relays, fluidics, optical or even mechanical elements.

Contents

Logic levels

A Boolean logical input or output always takes one of two logic levels. These logic levels can go by many names including: on / off, high (H) / low (L), one (1) / zero (0), true (T) / false (F), positive / negative, positive / ground, open circuit / close circuit, potential difference / no difference.

For consistency, the names 1 and 0 will be used below.

Logic gate

A logic gate takes one or more logic-level inputs and produces a single logic-level output. Because the output is also a logic level, an output of one logic gate can connect to the input of one or more other logic gates. Two outputs cannot be connected together, however, as they may be attempting to produce different logic values. In electronic logic gates, this would cause a short circuit.

In electronic logic, a logic level is represented by a certain voltage (which depends on the type of electronic logic in use). Each logic gate requires power so that it can source and sink currents to achieve the correct output voltage. In logic circuit diagrams the power is not shown, but in a full electronic schematic, power connections are required.

Basic logic gates and mechanical equivalents

While semiconductor electronic logic (see later) is preferred in most applications, relays and switches are still used in some industrial applications and for educational purposes. In this article, the various types of logic gates are illustrated with drawings of their relay-and-switch implementations, although the reader should remember that these are electrically different from the semiconductor equivalents that are discussed later.

Relay logic was historically important in industrial automation (see ladder logic and programmable logic controller). In relay logic, the two logic levels are 'open circuit' and 'closed circuit'. The electrical signal is extra, it can be of any voltage and any current, and can also flow in either direction.

In electronic circuits, logic levels are fixed voltage levels. It is not possible to pass any other signal through the gates, as the logic levels are the only voltages possible. For more information about how modern semiconductor logic gates work, see CMOS.

The three types of essential logic gate are the AND, the OR and the NOT gate. With these three, any conceivable Boolean equation can be implemented. However, for convenience, the derived types NAND, NOR, XOR and XNOR are also used, which often use fewer circuit elements for a given equation than an implementation based solely on AND, OR and NOT would do. In fact, the NAND has the lowest component count of any gate apart from NOT when implemented using modern semiconductor techniques, and since a NAND can implement both a NOT and, by application of De Morgan's Law, an OR function, this single type can effectively replace AND, OR and NOT, making it the only type of gate that is needed in a real system. Programmable logic arrays will very often contain nothing but NAND gates to simplify their internal design.

AND gates

INPUT OUTPUT
A B A AND B
0 0 0
1 0 0
0 1 0
1 1 1

Switch circuit diagram for AND gate

Switch circuit diagram for AND gate

The first example is the AND gate, whose truth table is shown below, left. The output is 1 when both inputs A and input B are 1. In all other cases the output is 0.

In the switch circuit, the circuit is closed when both A and B switches are pressed, otherwise the circuit is open.

OR gates

 

INPUT OUTPUT
A B A OR B
0 0 0
1 0 1
0 1 1
1 1 1

Switch circuit diagram for OR gate

Switch circuit diagram for OR gate

Another important arrangement is the OR gate, whose truth table is shown below, left. The output is 1 when input A or input B is 1. The output is also 1 when both inputs are 1.

In the switch circuit, the circuit is closed when switch A or switch B (or both) are pressed, else the circuit is open.

NOT gates

 

INPUT OUTPUT
A NOT A
0 1
1 0

Switch circuit diagram for NOT gate

Switch circuit diagram for NOT gate

A simpler arrangement is the NOT gate, whose truth table is shown opposite. In the NOT gate the output is the logical opposite of the input. This means if the input is 1, the output is 0, and if the input is 0 the output is 1.

In the switch circuit, a normally closed switch is used, making a closed circuit. If the switch is pushed the circuit becomes open circuit.

NAND

 

INPUT OUTPUT
A B A NAND B
0 0 1
1 0 1
0 1 1
1 1 0

Switch circuit diagram of NAND gate

Switch circuit diagram of NAND gate

The NAND gate is the NOT of an AND gate. That is, the output is 1 when NOT (A AND B are 1), as shown in the truth table.

NOR

 

INPUT OUTPUT
A B A NOR B
0 0 1
1 0 0
0 1 0
1 1 0

Switch circuit diagram of NOR gate

Switch circuit diagram of NOR gate

The NOR gate is the NOT of an OR gate. That is, the output is 1 only when both inputs are 0, as shown in the truth table.

XOR and XNOR gates

There exist two other 'basic' logic gates - XOR (exclusive-OR) and XNOR (exclusive-NOR).

INPUT OUTPUT
A B A XOR B
0 0 0
0 1 1
1 0 1
1 1 0

XOR is a 'stricter' version of the OR gate. Rather than allowing the output to be 1 when either one or both of the inputs are 1, an XOR gate has a 1 output only when only one input is 1. Thus, it has the truth table shown to the right. This can also be interpreted (for a two-input gate) as "1 output when the inputs are different".


INPUT OUTPUT
A B A XNOR B
0 0 1
1 0 0
0 1 0
1 1 1

XNOR is an inverted version of the XOR gate. Thus, it has the truth table shown to the right. This can also be interpreted as "1 output when the inputs are same".

The preceding simple logic gates can be combined to form more complicated Boolean logic circuits. Logic circuits are often classified in two groups: combinatorial logic, in which the outputs are continuous-time functions of the inputs, and sequential logic, in which the outputs depend on information stored by the circuits as well as on the inputs.


Background

The simplest form of electronic logic is diode logic. This allows AND and OR gates to be built, but not inverters, and so is an incomplete form of logic. To build a complete logic system, valves or transistors can be used. The simplest family of logic gates using bipolar transistors is called resistor-transistor logic, or RTL. Unlike diode logic gates, RTL gates can be cascaded indefinitely to produce more complex logic functions. These gates were used in early integrated circuits. For higher speed, the resistors used in RTL were replaced by diodes, leading to diode-transistor logic, or DTL. It was then discovered that one transistor could do the job of two diodes in the space of one diode, so transistor-transistor logic, or TTL, was created. In some types of chip, to reduce size and power consumption still further, the bipolar transistors were replaced with complementary field-effect transistors (MOSFETs), resulting in complementary metal-oxide-semiconductor (CMOS) logic.

For small-scale logic, designers now use prefabricated logic gates from families of devices such as the TTL 7400 series invented by Texas Instruments and the CMOS 4000 series invented by RCA, and their more recent descendants. These devices usually contain transistors with multiple emitters, used to implement the AND function, which are not available as separate components. Increasingly, these fixed-function logic gates are being replaced by programmable logic devices, which allow designers to pack a huge number of mixed logic gates into a single integrated circuit. The field-programmable nature of programmable logic devices such as FPGAs has removed the 'hard' property of hardware; it is now possible to change the logic design of a hardware system by reprogramming some of its components, thus allowing the features or function of a hardware implementation of a logic system to be changed.

Electronic logic gates differ significantly from their relay-and-switch equivalents. They are much faster, consume much less power, and are much smaller (all by a factor of a million or more in most cases). Also, there is a fundamental structural difference. The switch circuit creates a continuous metallic path for current to flow (in either direction) between its input and its output. The semiconductor logic gate, on the other hand, acts as a high-gain voltage amplifier, which sinks a tiny current at its input and produces a low-impedance voltage at its output. It is not possible for current to flow between the output and the input of a semiconductor logic gate.

Another important advantage of standardised semiconductor logic gates, such as the 7400 and 4000 families, is that they are cascadable. This means that the output of one gate can be wired to the inputs of one or several other gates, and so on ad infinitum, enabling the construction of circuits of arbitrary complexity without requiring the designer to understand the internal workings of the gates.

In practice, the output of one gate can only drive a finite number of inputs to other gates, a number called the 'fanout limit', but this limit is rarely reached in the newer CMOS logic circuits, as compared to TTL circuits. Also, there is always a delay, called the 'propagation delay', from a change in input of a gate to the corresponding change in its output. When gates are cascaded, the total propagation delay is approximately the sum of the individual delays, an effect which can become a problem in high-speed circuits.

Electronic Logic levels

The two logic levels in binary logic circuits can be described as two voltage ranges, "zero" and "one", or "high" and "low". Each technology has its own requirements for the voltages used to represent the two logic levels, to ensure that the output of any device can reliably drive the input of the next device. Usually, two non-overlapping voltage ranges, one for each level, are defined. The difference between the high and low levels ranges from 0.7 volts in ECL logic to around 28 volts in relay logic.

Logic gates and hardware

NAND and NOR logic gates are the two pillars of logic, in that all other types of Boolean logic gates (i.e., AND, OR, NOT, XOR, XNOR) can be created from a suitable network of just NAND or just NOR gate(s). They can be built from relays or transistors, or any other technology that can create an inverter and a two-input AND or OR gate.

These functions can be seen in the table below.

OR Any high input will drive the output high
NOR Any high input will drive the output low
AND Any low input will drive the output low
NAND Any low input will drive the output high

Logic gates are a vital part of many digital circuits, and as such, every kind is available as an IC. For examples, see the 4000 series of CMOS logic chips.

Symbols

There are two sets of symbols in common use, both now defined by ANSI/IEEE Std 91-1984 and its supplement ANSI/IEEE Std 91a-1991. The "distinctive shape" set, based on traditional schematics, is used for simple drawings and is quicker to draw by hand. It is sometimes unofficially described as "military", reflecting its origin if not its modern usage. The "rectangular shape" set, based on IEC 60617-12, has rectangular outlines for all types of gate, and allows representation of a much wider range of devices than is possible with the traditional symbols. The IEC's system has been adopted by other standards, such as EN 60617-12:1999 in Europe and BS EN 60617-12:1999 in the United Kingdom.

Type Distinctive shape Rectangular shape
AND AND symbol AND symbol
OR OR symbol OR symbol
NOT NOT symbol NOT symbol
In electronics a NOT gate is more commonly called an inverter. The circle on the symbol is called a bubble, and is generally used in circuit diagrams to indicate an inverted input or output.
NAND NAND symbol NAND symbol
NOR NOR symbol NOR symbol
In practice, the cheapest gate to manufacture is usually the NAND gate. Additionally, Charles Peirce showed that NAND gates alone (as well as NOR gates alone) can be used to reproduce all the other logic gates.

Symbolically, a NAND gate can also be shown using the OR shape with bubbles on its inputs, and a NOR gate can be shown as an AND gate with bubbles on its inputs. This reflects the equivalency due to De Morgans law, but it also allows a diagram to be read more easily, or a circuit to be mapped onto available physical gates in packages easily, since any circuit node that has bubbles at both ends can be replaced by a simple bubble-less connection and a suitable change of gate. If the NAND is drawn as OR with input bubbles, and a NOR as AND with input bubbles, this gate substitution occurs automatically in the diagram (effectively, bubbles "cancel"). This is commonly seen in real logic diagrams - thus the reader must not get into the habit of associating the shapes exclusively as OR or AND shapes, but also take into account the bubbles at both inputs and outputs in order to determine the "true" logic function indicated.

Two more gates are the exclusive-OR or XOR function and its inverse, exclusive-NOR or XNOR. The two input Exclusive-OR is true only when the two input values are different, false if they are equal, regardless of the value. If there are more than two inputs, the gate generates a true at its output if the number of trues at its input is odd. In practice, these gates are built from combinations of simpler logic gates.

XOR XOR symbol XOR symbol
XNOR XNOR symbol XNOR symbol

The 7400 chip, containing four NAND's. The two additional contacts supply power (+5 V) and connect the ground.

The 7400 chip, containing four NAND's. The two additional contacts supply power (+5 V) and connect the ground.

DeMorgan equivalent symbols

By use of De Morgan's theorem, an AND gate can be turned into an OR gate by inverting the sense of the logic at its inputs and outputs. This leads to a separate set of symbols with inverted inputs and the opposite core symbol. These symbols can make circuit diagrams for circuits using active low signals much clearer and help to show accidental connection of an active high output to an active low input or vice-versa.

Storage of bits

Related to the concept of logic gates (and also built from them) is the idea of storing a bit of information. The gates discussed up to here cannot store a value: when the inputs change, the outputs immediately react. It is possible to make a storage element either through a capacitor (which stores charge due to its physical properties) or by feedback. Connecting the output of a gate to the input causes it to be put through the logic again, and choosing the feedback correctly allows it to be preserved or modified through the use of other inputs. A set of gates arranged in this fashion is known as a "latch", and more complicated designs that utilise clocks (signals that oscillate with a known period) and change only on the rising edge are called edge-triggered "flip-flops". The combination of multiple flip-flops in parallel, to store a multiple-bit value, is known as a register.

These registers or capacitor-based circuits are known as computer memory. They vary in performance, based on factors of speed, complexity, and reliability of storage, and many different types of designs are used based on the application.

Three-state logic gates

Three-state, or 3-state, logic gates have three states of the output: high (H), low (L) and high-impedance (Z). The high-impedance state plays no role in the logic, which remains strictly binary. These devices are used on buses to allow multiple chips to send data. A group of three-states driving a line with a suitable control circuit is basically equivalent to a multiplexer, which may be physically distributed over separate devices or plug-in cards.

'Tri-state', a widely-used synonym of 'three-state', is a trademark of the National Semiconductor Corporation.

Miscellaneous

Logic circuits include such devices as multiplexers, registers, ALUs, and computer memory, all the way up through complete microprocessors which can contain more than a 100 million gates. In practice, the gates are made from field effect transistors (FETs), particularly metal-oxide-semiconductor FETs (MOSFETs).

In reversible logic, Toffoli gates are used.

History and development

The earliest logic gates were made mechanically. Charles Babbage, around 1837, devised the Analytical Engine. His logic gates relied on mechanical gearing to perform operations. Electromagnetic relays were later used for logic gates. In 1891, Almon Strowger patented a device containing a logic gate switch circuit. Strowger's patent was not in widespread use until the 1920s. Starting in 1898, Nikola Tesla filed for patents of devices containing logic gate circuits. Eventually, vacuum tubes replaced relays for logic operations. Lee De Forest's modification, in 1907, of the Fleming valve can be used as AND logic gate. Claude E. Shannon introduced the use of Boolean algebra in the analysis and design of switching circuits in 1937. Walther Bothe, inventor of the coincidence circuit, got part of the 1954 Nobel Prize in physics, for the first modern electronic AND gate in 1924. Active research is taking place in molecular logic gates.

Common Basic Logic ICs

CMOS TTL Function
4001 7402 Quad two-input NOR gate
4011 7400 Quad two-input NAND gate
4049 7404 Hex NOT gate (inverting buffer)
4070 7486 Quad two-Input XOR gate
4071 7432 Quad two-input OR gate
4077 74266 Quad two-input XNOR gate
4081 7408 Quad two-input AND gate

Back

To Top