XOR gate
Encyclopedia
INPUT
A   B
OUTPUT
A XOR B
0 0 0
0 1 1
1 0 1
1 1 0

The XOR gate (sometimes EOR gate, or EXOR gate) is a digital logic gate
Logic gate
A logic gate is an idealized or physical device implementing a Boolean function, that is, it performs a logical operation on one or more logic inputs and produces a single logic output. Depending on the context, the term may refer to an ideal logic gate, one that has for instance zero rise time and...

 that implements an exclusive or; that is, a true output (1) results if one, and only one, of the inputs to the gate is true (1). If both inputs are false (0) or both are true (1), a false output (0) results. Its behavior is summarized in the truth table shown on the right. A way to remember XOR is "one or the other but not both". It represents the inequality function, i.e., the output is HIGH (1) if the inputs are not alike otherwise the output is LOW (0).

This function is addition modulo 2. As a result, XOR gates are used to implement binary addition in computers. A half adder consists of an XOR gate and an AND gate
AND gate
The AND gate is a basic digital logic gate that implements logical conjunction - it behaves according to the truth table to the right. A HIGH output results only if both the inputs to the AND gate are HIGH . If neither or only one input to the AND gate is HIGH, a LOW output results...

.

Symbols

There are two symbols for XOR gates: the 'military' symbol which was originally developed in America and the 'rectangular' symbol, which was originally British. For more information see Logic Gate Symbols.


The XOR gate with inputs A and B implements the logical expression .

Alternatives

If a specific type of gate is not available, it can be constructed from other available gates. An XOR gate can be trivially constructed from an XNOR gate followed by a NOT gate. If we consider the expression , we can construct an XOR gate directly using AND, OR and NOT gates. However, this approach requires four gates of three different kinds.

An XOR gate can be made from four NAND or five NOR gates in the configurations shown below. In fact, both NAND and NOR gates are so-called "universal gates," and any logical function can be constructed from either NAND logic
NAND logic
NAND gates are one of the two basic logic gates from which any other logic gates can be built. Due to this property, NAND and NOR gates are sometimes called "universal gates". However, modern integrated circuits are not constructed exclusively from a single type of gate...

 or NOR logic
NOR logic
Like NAND gates, NOR gates are so-called "universal gates" that can be combined to form any other kind of logic gate. For example, the first embedded system, Apollo Guidance Computer, was built exclusively from NOR gates, about 5,600 in total for the later versions. Today, integrated circuits are...

 alone.



More than two inputs

Strict reading of the definition of exclusive or, or observation of the IEC symbol, raises the question of correct behaviour with additional inputs. If a logic gate were to accept three or more inputs and produce a true output if exactly one of those inputs were true, then it would in effect be a one-hot detector (and indeed this is the case for only two inputs). However, it is rarely implemented this way in practice.

It is most common to regard subsequent inputs as being applied through a cascade of binary exclusive-or operations: the first two signals are fed into an XOR gate, then the output of that gate is fed into a second XOR gate together with the third signal, and so on for any remaining signals. The result is a circuit that outputs a 1 when the number of 1s at its inputs is odd, and a 0 when the number of incoming 1s is even. This makes it practically useful as a parity generator or a modulo-2 adder
Adder (electronics)
In electronics, an adder or summer is a digital circuit that performs addition of numbers.In many computers and other kinds of processors, adders are used not only in the arithmetic logic unit, but also in other parts of the processor, where they are used to calculate addresses, table indices, and...

.

For example, the 74LVC1G386 microchip is advertised as a three-input logic gate, and implements a parity generator.

The Verilog
Verilog
In the semiconductor and electronic design industry, Verilog is a hardware description language used to model electronic systems. Verilog HDL, not to be confused with VHDL , is most commonly used in the design, verification, and implementation of digital logic chips at the register-transfer level...

 reduction operators can also take an arbitrary number of single-bit inputs into a single exclusive-or operation, producing a single-bit result. Here the output is also defined as a parity operation.

Uses in Addition

The XOR logic gate can be used as a one-bit adder
Adder (electronics)
In electronics, an adder or summer is a digital circuit that performs addition of numbers.In many computers and other kinds of processors, adders are used not only in the arithmetic logic unit, but also in other parts of the processor, where they are used to calculate addresses, table indices, and...

 that adds any two bits together to output one bit. For example, if we add 1 plus 1 in binary
Binary numeral system
The binary numeral system, or base-2 number system, represents numeric values using two symbols, 0 and 1. More specifically, the usual base-2 system is a positional notation with a radix of 2...

, we expect a two-bit answer, 10 (i.e. 2 in decimal). Since the trailing sum bit in this output is achieved with XOR, the preceding carry bit is calculated with an AND gate
AND gate
The AND gate is a basic digital logic gate that implements logical conjunction - it behaves according to the truth table to the right. A HIGH output results only if both the inputs to the AND gate are HIGH . If neither or only one input to the AND gate is HIGH, a LOW output results...

. This is the main principle in Half Adders and the combined AND-XOR circuit may be chained together in order to add ever longer binary numbers.

Signal crossing

XOR gates can be used to cross two Boolean signals without requiring a via
Via (electronics)
A via is a vertical electrical connection between different layers of conductors in a physical electronic circuit.- In IC :In integrated circuit design, a via is a small opening in an insulating oxide layer that allows a conductive connection between different layers. A via on an integrated circuit...

. The crossover comprises three XOR gates, strategically positioned to cancel out the effects of each other. A similar result can be achieved using eight NAND gate
NAND gate
The Negated AND, NO AND or NAND gate is the opposite of the digital AND gate, and behaves in a manner that corresponds to the opposite of AND gate, as shown in the truth table on the right. A LOW output results only if both the inputs to the gate are HIGH...

s. Note that this setup can only cross Boolean (digital) signals, and not analog signals, so would be of limited use in an amplifier or other analog circuit.

Pseudo-random number generation

Pseudo-random number generators, specifically Linear feedback shift register
Linear feedback shift register
A linear feedback shift register is a shift register whose input bit is a linear function of its previous state.The most commonly used linear function of single bits is XOR...

s
, are defined in terms of the exclusive-or operation. Hence, a suitable setup of XOR gates can model a linear feedback shift register, in order to generate random sequences of bits.

See also

  • Exclusive or
  • XNOR gate
    XNOR gate
    The XNOR gate is a digital logic gate whose function is the inverse of the exclusive OR gate. The two-input version implements logical equality, behaving according to the truth table to the right. A HIGH output results if both of the inputs to the gate are the same...

  • Boolean algebra (logic)
  • Logic gates
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK