A digital comparator (or magnitude comparator) is a combinational circuit that compares two binary numbers and indicates whether the first is greater than, equal to, or less than the second. It produces three mutually exclusive outputs — A>B, A=B and A<B. Comparators appear in ALUs, sorting hardware, address decoding and control logic. This guide covers the 1-bit and 2-bit designs and how they scale.
1-bit comparator
Comparing single bits A and B:
| A | B | A>B | A=B | A<B |
|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 0 |
Boolean expressions:
A>B = A · B'A=B = A ⊙ B = (A ⊕ B)'(XNOR — equality)A<B = A' · B
Notice equality is exactly the XNOR gate — which is why XNOR is often called the equality gate.
Multi-bit comparison
To compare two n-bit numbers, compare from the most significant bit (MSB) down. The rule:
- Compare the MSBs. If they differ, that decides the result (the number with MSB = 1 is larger).
- If the MSBs are equal, move to the next bit and repeat.
- If all bits are equal, A = B.
Each bit stage uses an XNOR to test equality and passes control to the next-lower bit only when the current bits match. This is why equality (XNOR) terms chain through the whole comparator.
2-bit comparator expressions
For A = A₁A₀ and B = B₁B₀, with e₁ = (A₁ ⊙ B₁) and e₀ = (A₀ ⊙ B₀):
A>B = A₁B₁' + e₁·A₀B₀'A=B = e₁ · e₀A<B = A₁'B₁ + e₁·A₀'B₀
Cascading comparators
Standard comparator ICs and IP blocks provide cascade inputs so several can be chained to compare wide words. The higher-order comparator’s result dominates; the cascade inputs only matter when the higher bits are equal — the same MSB-first priority as above.
Where comparators are used
Inside ALUs for branch and conditional instructions, in address decoders (is this address in my range?), in priority and arbitration logic, and in sorting/searching hardware. A comparator is purely combinational, so its result is valid after the propagation delay of its gate chain.
FAQs on digital comparators
What is a digital comparator?
A combinational circuit that compares two binary numbers and outputs whether the first is greater than, equal to, or less than the second.
Which gate is used to check equality?
The XNOR gate — it outputs 1 only when its two inputs are equal, so an XNOR per bit (ANDed together) detects whole-number equality.
How does a multi-bit comparator work?
It compares from the most significant bit down. The first differing bit decides the result; lower bits only matter when all higher bits are equal.
Is a comparator combinational or sequential?
Combinational — its outputs depend only on the current input numbers, with no memory or clock.
Learn combinational and datapath design in ChipXpert’s RTL Design course. Related: combinational circuits, logic gates.
Related digital electronics topics
- JK Flip-Flop: Truth Table & Working
- T Flip-Flop: Truth Table & Circuit
- D Flip-Flop & D Latch
- SR Latch (NAND & NOR)
- Karnaugh Map (K-Map)
- Full Adder & Half Adder
- Universal Gates: NAND & NOR
- Finite State Machines (FSM)
- Sequential Circuits
- Shift Registers (SISO/SIPO/PISO/PIPO)
- 4:1 Multiplexer
- Encoders & Decoders
- Binary to Gray Code Conversion
- One's & Two's Complement
- Counters in Digital Electronics
- Demultiplexer (DEMUX)
- Logic Gates: Types & Truth Tables
- Boolean Algebra & De Morgan's Theorem
- Number Systems (Binary, Octal, Hex)
- Combinational Circuits
- Half Subtractor & Full Subtractor
- Latch vs Flip-Flop
- Setup Time & Hold Time
- Master-Slave Flip-Flop
- Ring Counter & Johnson Counter
Share your question in comments or talk to our mentor team for batch guidance.
Ask the Admin Team
Drop your basic question in comments: eligibility, prerequisites, tools, fee range, and placement support.
Our team reviews and responds regularly.
