Back to course

Comparators (Magnitude Comparators)

Digital Logic Systems: From Zero to Hero

27. Comparators (Magnitude Comparators)

A Magnitude Comparator is a combinational circuit that determines the relationship between two binary numbers, A and B.

Outputs

The comparator provides three mutually exclusive outputs:

  1. $A > B$ (A is greater than B)
  2. $A = B$ (A is equal to B)
  3. $A < B$ (A is less than B)

1-Bit Comparator Design

For two single bits, $A$ and $B$:

  • $A = B$: This happens if $A$ and $B$ are the same (00 or 11). This is the XNOR function. $E = A \odot B$
  • $A > B$: This only happens if $A=1$ and $B=0$. $G = A \overline{B}$
  • $A < B$: This only happens if $A=0$ and $B=1$. $L = \overline{A} B$

N-Bit Comparator

For multi-bit numbers, comparison starts from the Most Significant Bit (MSB). If $A_{n-1} \ne B_{n-1}$, that bit determines the relationship. If $A_{n-1} = B_{n-1}$, we move to the next bit down, requiring cascaded logic.

General $A > B$ Logic (starting from MSB): $$G = G_{n-1} + E_{n-1} G_{n-2} + E_{n-1} E_{n-2} G_{n-3} + \dots$$ Where $G_i$ is $A_i \overline{B_i}$ (A > B at stage i), and $E_i$ is $A_i \odot B_i$ (A = B at stage i).