2-Bit Comparator

A magnitude comparator compares two binary numbers and says which is bigger. This one takes AB and CD — two 2-bit numbers — and lights exactly one of three outputs: AB > CD, AB = CD or AB < CD.

Try it live

This is the Circuit Simulator itself, running in the page — it is LogicsBench's own example design, read-only. Open it full size, and sign in to make your own copy to change.

  • Set AB to 10 (two) and CD to 01 (one): only AB>CD lights.
  • Open the Truth table tab and check that exactly one output is 1 on every row.

2-bit comparator truth table

ABCDAB>CDAB=CDAB<CD
0000010
0001001
0010001
0011001
0100100
0101010
0110001
0111001
1000100
1001100
1010010
1011001
1100100
1101100
1110100
1111010

How it works

  • AB>CD = AC′ + BC′D′ + ABD′
  • AB=CD = (A ⊙ C)(B ⊙ D)
  • AB<CD = A′C + A′B′D + B′CD

The most significant bits decide first: if A and C differ, the number with the 1 is bigger, whatever B and D are.

Only when A equals C do B and D get a say.

Equal needs every bit to match — an XNOR per bit, ANDed. The 74LS85 does the same for four bits, and chains for more.

Building it from 74-series chips

74LS04inverters for A′, B′, C′, D′
74LS08 / 74LS11the product terms
74LS32OR gates to join them
74LS85or a 4-bit comparator in one chip

More example circuits

Build your own.

The Circuit Simulator is free, in your browser — start from a blank page or from this example.