One-bit comparator

Is A greater, equal, or less than B? Exactly one lamp will tell you. A ready-made arithmetic circuit you can open in the TorchAnvil simulator.

Three questions, one circuit

Given two bits, there are only three possible relationships between them: A is bigger, A equals B, or A is smaller. A one-bit comparator answers all three at once, lighting exactly one of three lamps for any input.

How it works

Each lamp has its own tiny formula:

Because the three conditions are mutually exclusive and cover every input, exactly one lamp is lit at any moment. Always. No matter what you do with the levers.

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

Why it matters

This is the building block for any magnitude comparator. To compare multi-bit numbers, you chain these from the most significant bit down: if the top bits differ, that's the answer; if they're equal, fall through to the next bit. The same "is A greater, equal, or less" cascade shows up in sorting networks, priority encoders, and every if (a > b) your CPU has ever evaluated.

Try this