Skip to content
BetterDL

Equality comparator

Also called: identity comparator, equality checker, equality detector, equal-to comparator

A comparator that outputs 1 exactly when two binary numbers are equal, built from one XNOR per bit position followed by an AND gate.

An equality comparator answers one question: are A and B the same number? Two numbers are equal exactly when every bit position matches.

That translates directly into gates:

  1. For each position i, an XNOR gives 1 when Aᵢ and Bᵢ agree.
  2. An AND of all those XNOR outputs is 1 only when every position agrees.

For 2-bit numbers: E = .

A single mismatch anywhere forces its XNOR to 0, and the AND drops to 0. An n-bit equality comparator costs n XNOR gates and one n-input AND.

The same circuit can be drawn the other way round: XOR gates flag mismatches, an OR collects them ("any mismatch?"), and a final NOT or a NOR turns that into "equal". By De Morgan, AND of XNORs and NOR of XORs are the same function.

It is the simplest kind of comparator. A magnitude comparator adds greater-than and less-than outputs.

Where it shows up: address matching (does this address belong to my chip?), checking a password or key code, and the zero test of an ALU (is the result equal to 0?).

A1A0B1B0E

Worked examples

Example

Two 2-bit numbers

A1A0 = 01, B1B0 = 00. Trace the circuit above.

  1. 1.

    Position 1: A1 = 0, B1 = 0 → XNOR = 1 (match).

  2. 2.

    Position 0: A0 = 1, B0 = 0 → XNOR = 0 (mismatch).

  3. 3.

    AND: 1 · 0 = 0. So E = 0: the numbers are not equal.

Example

Sizing a 4-bit comparator

Compare A = 0110 with B = 0110, and count the gates.

  1. 1.

    Each position matches, so all four XNORs output 1.

  2. 2.

    The 4-input AND gives E = 1.

  3. 3.

    Gates: 4 XNORs and one 4-input AND.

Common mistakes

  • Using XOR outputs directly. XOR is 1 on a mismatch, so ANDing XORs detects "every bit differs", not equality.

  • ORing the XNOR outputs. That gives 1 if any position matches; equality needs all of them.

  • Pairing the wrong bits, such as A1 with B0. Each XNOR must compare bits of the same weight.

Practice Equality comparator

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Equality comparator is taught in Combinational Logic.