XOR and XNOR

XOR and XNOR

The Exclusive OR (or XOR) relationship $F = A\oplus B$ is defined by the truth tables shown in Fig. 1 and the equivalent two-variable logic expressions $F_{SOP}=A\cdot \overline{B} + \overline{A}\cdot B$ and $F_{POS} = (A+B)\cdot (\overline{A} + \overline{B})$.

Figure 1. XOR truth table ($F=A\oplus B$, $F'=A\oplus B\oplus C$).

The XOR function is frequently used in digital circuits to manipulate signals that represent binary numbers—these circuits will be presented in a later module. For now, note the XOR output is asserted whenever an odd number of inputs are asserted. This “odd detector” nature of the XOR relationship holds for any number of inputs.

Compound XOR functions like $F = A \oplus(B\cdot C)$ can always be written in an equivalent SOP or POS forms:

$F_{SOP}=A\cdot \overline{B\cdot C} + \overline{A}\cdot (B\cdot C)$ and $F_{POS} = (A+B\cdot C)\cdot (\overline{A} + \overline{B\cdot C})$.

The XNOR function is the inverse of the XOR function. Since the output of a 2-input XNOR is asserted when both inputs are the same, it is sometimes referred to as the Equivalence function (EQV), but this name is misleading because it does not hold for three or more variables (i.e., the output of a 3-input XNOR is not asserted whenever all three inputs are the same). Truth tables for 2 and 3 input XNOR functions are shown in Fig. 2, and it can be seen that for each combination of inputs, the output is the inverse of the XOR truth tables above. The Exclusive NOR (or XNOR) relationship $F = \overline{A \oplus B}$ shown in the truth tables has the equivalent two-variable logic expressions:

$F_{SOP}=\overline{A}\cdot \overline{B} + A\cdot B$ and $F_{POS} = (\overline{A}+B)\cdot (A + \overline{B})$.

Figure 2. Xnor truth table ($F=\overline{A\oplus B}$, $F'=\overline{A\oplus B\oplus C}$).

If either the A or B inputs are in the XNOR truth table inverted, then XOR outputs are produced; that is, $F = \overline{A \oplus B}$ produces the same logic output as $F = \overline{A}\oplus B$ or $F = A \oplus \overline{B}$. If both the A and B inputs are inverted, XNOR outputs are still produced: $F = \overline{A \oplus B}$ produces the same output as $F = \overline{\overline{A} \oplus \overline{B}}$. This same property holds for the XOR function—inverting any single input variable will result in XNOR function, and inverting two inputs will again produce the XOR function. In fact, this property can be generalized to XOR/XNOR functions of any number of inputs: any single input inversion changes the function output between the XOR and XNOR functions; any two input signal inversions does not change function outputs; any three input signal inversions changes the function output between the XOR and XNOR functions, etc. More succinctly, inverting an odd number of inputs changes an XOR to an XNOR and vice-versa, inverting an even number of inputs changes nothing, and inverting the entire function has the same effect as inverting a single input. Some representative cases are shown. \[\begin{align} F=\overline{A\oplus B\oplus C} &\iff F=\overline{A} \oplus B\oplus C &\iff F=\overline{A}\oplus \overline{B}\oplus \overline{C} \\ F=A\oplus B\oplus C & \iff F=\overline{A}\oplus \overline{B}\oplus C &\iff F=\overline{A\oplus \overline{B} \oplus C} \end{align}\] An even more succinct description of the XOR and XNOR function outputs can be drawn from the properties discussed. The XOR output is asserted whenever an odd number of inputs are asserted, and the XNOR is asserted whenever an even number of inputs are asserted: the XOR is an odd detector, and the XNOR an even detector. This very useful property will be exploited in data error detection circuits discussed later.

XOR and XNOR gate symbols are shown below in Fig. 3. CMOS circuits for either function can be can built from just 6 transistors, but those circuits have some undesirable features. More typically, XOR and XNOR logic gates are built from three NAND gates and two inverters, and so take 16 transistors.

Figure 3. CMOS implementation of XOR and XNOR gates.

A useful application of the XOR function is the “controlled inverter” circuit illustrated below in Fig. 4. The truth table, derived directly from the XOR truth table, uses an XOR gate with one input tied to a signal named “control”. When control is a '1' the input A is inverted, but when control is a '0' A is simply passed through the logic gate without modification. This controlled inversion function will be useful in later work.

Figure 4. XOR gate can be thought of as a controlled inverter.

Important Ideas

  • The XOR output is asserted whenever an odd number of inputs are asserted, and the XNOR is asserted whenever an even number of inputs are asserted: the XOR is an odd detector, and the XNOR, an even detector.
  • Any odd number of input inversion changes the function output between the XOR and XNOR functions; any even number of input signal inversions does not change function outputs; any three input signal inversions changes the function output
  • Xor gate can be used as a “controlled inverter”.

  • Other product and company names mentioned herein are trademarks or trade names of their respective companies. © 2014 Digilent Inc. All rights reserved.