XOR and XNOR

Introduction to Logic Fundamentals

1848

Exclusive OR (XOR) and Exclusive NOR (XNOR)

The Exclusive OR (or XOR) relationship F=ABF=A⊕B is defined by the truth tables shown in Fig. 1 and the equivalent two-variable logic expressions

FSOP=AB+ABF\_{SOP} = A \cdot \overline B + \overline A \cdot B and FPOS=(A+B)(A+B)F\_{POS}=(A+B) \cdot (\overline A + \overline B).

Figure 1. XOR truth table
Figure 1. XOR truth table

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(BC)F=A⊕(B \cdot C) can always be written in an equivalent SOP or POS forms:

FSOP=ABC+ABCF\_{SOP} = A \cdot \overline{B \cdot C} + \overline A \cdot B \cdot C

FPOS=(A+BC)(A+BC)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=ABF=\overline{A⊕B} shown in the truth tables has the equivalent two-variable logic expressions:

FSOP=AB+ABF\_{SOP} = \overline A \cdot \overline{B} + A \cdot B

FPOS=(A+B)(A+B)F\_{POS}=(\overline A + B) \cdot (A + \overline{B})

Figure 2. Xnor truth table
Figure 2. Xnor truth table

If either the A or B inputs are in the XNOR truth table inverted, then XOR outputs are produced; that is, F=ABF=\overline{A⊕B} produces the same logic output as F=ABF=\overline A⊕B or F=ABF=A⊕ \overline B. If both the A and B inputs are inverted, XNOR outputs are still produced: F=ABF=\overline{A⊕B} produces the same output as F=ABF=\overline{\overline A⊕ \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.

F=ABCF=ABCF=ABCF=\overline{A⊕B⊕C} \iff F=\overline A⊕B⊕C \iff F=\overline A⊕\overline B⊕\overline C

F=ABCF=ABCF=ABC F=A⊕B⊕C \iff F=\overline A⊕\overline B⊕C \iff F=\overline{A⊕\overline B⊕C} \space

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.
Figure 3. CMOS implementation of XOR and XNOR gates.
Figure 4. XOR gate can be thought of as a controlled inverter.
Figure 4. XOR gate can be thought of as a controlled inverter.

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.

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”.