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:
- For each position i, an XNOR gives 1 when Aᵢ and Bᵢ agree.
- 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?).