LearnGates

The equality comparator: are two numbers equal?

A comparator tells whether two numbers are equal. Here both numbers have 2 bits: A1 A0 and B1 B0. The output EQ must be 1 when they are the same number and 0 otherwise.

Truth table

Truth table of Equality comparator
A1A0B1B0EQ
00001
00010
00100
00110
01000
01011
01100
01110
10000
10010
10101
10110
11000
11010
11100
11111

Try it Click the inputs to change them.

EQ1

How it works

Two numbers are equal when every pair of matching bits is equal. The XNOR gate is 1 exactly when its two inputs are equal, so one XNOR compares A1 with B1 and another compares A0 with B0. The numbers are equal only if both comparisons say yes: join them with an AND gate.

For 8-bit numbers you would use eight XNORs and one AND with eight inputs. Processors do this every time a program checks whether two values are equal.

Hints and solution

Try on your own first. Each hint gives away a little more.

  1. Compare bit by bit: XNOR is 1 when its inputs are equal.
  2. Both bit pairs must be equal.