4-bit equality comparator from XOR gates

edge caseXOR trees as comparators

Answer

EQ 1 on 16 of 256 patterns

Why this example is worth doing

XOR each pair of corresponding bits, OR the results, and the output is 0 exactly when the two words are equal — an n-bit equality comparator in n + 1 gates. The page builds it for four bits and points out that the same structure with the OR replaced by an XOR tree computes parity instead, so one layout serves two standard components. It links to the parity tool for the second reading.

Try your own input in the XOR gate. Truth table, symbol and algebraic form for A ⊕ B, the difference detector.

How the answer is reached

Output table

Output table — columns A3, A2, A1, A0, B3, B2, B1, B0, EQ
A3A2A1A0B3B2B1B0EQ
000000001
000000010
000000100
000000110
000001000
000001010
000001100
000001110
000010000
000010010
000010100
000010110
000011000
000011010
000011100
000011110
000100000
000100011
000100100
000100110
000101000
000101010
000101100
000101110
000110000
000110010
000110100
000110110
000111000
000111010
000111100
000111110
Warning:

First 32 of 256 rows; the full table is 256 rows deep.

Compare with

Open the XOR gate

This input is entered in the tool itself — it is too rich for a link to carry.

Note:

Notation this page assumes

  • Symbols: · is AND, + is OR, ⊕ is XOR, a prime or an overline is NOT. The field also takes ∧ ∨ ¬ ~ ! & | and the words.
  • Operator precedence, tightest first: NOT, then AND (including juxtaposition), then XOR/XNOR, then NAND/NOR, then OR, then IMPLIES, then IFF.
  • Gate symbols follow whichever standard the header toggle is set to: ANSI/IEEE Std 91-1984 distinctive shapes, or IEC 60617-12 rectangles.

Sources

  • ANSI/IEEE Std 91-1984, Graphic Symbols for Logic Functions
  • IEC 60617-12, Graphical Symbols for Diagrams — Binary Logic Elements