Computing Library › Classical Logic Gates
Classical Logic Gates

Digital Comparator

A comparator compares two binary numbers and reports whether one is equal to, greater than, or less than the other.

What it does

A digital comparator takes two binary values and produces relational outputs: equal, greater than, and less than. It is a combinational function, its result depending only on the two current inputs.

One-bit comparison

Kronos motion — classical
ABA=BA>BA<B
00100
01001
10010
11100

Gate equations for one bit

Comparing multi-bit words

Words are equal only when every bit pair matches, so equality is the AND of the per-bit XNOR results. Ordering is decided from the most significant bit down: the first position where the words differ determines which is larger, and lower positions matter only when all higher bits are equal.

In code

python
def compare(a, b):
    if a == b: return 'eq'
    return 'gt' if a > b else 'lt'

Where it appears

Comparators drive conditional branches, sort and search hardware, threshold detectors, and address-range checks. The equality path reuses the same XNOR-and-AND structure described for the XNOR gate, while the ordering path adds the greater-than and less-than terms.