Skip to content
BetterDL

Magnitude comparator

Also called: greater-than comparator, less-than comparator, G E L comparator, 2-bit comparator

A comparator with outputs G (A > B), E (A = B) and L (A < B). The most significant bit position where the numbers differ decides which is larger.

A magnitude comparator tells you how two unsigned binary numbers relate. It usually has three outputs, and exactly one of them is 1:

  • G = 1 when A > B
  • E = 1 when A = B
  • L = 1 when A < B

One bit. G = , E = , L = .

More bits. Compare like a dictionary: look at the MSB first. If the top bits differ, they decide everything. Only if they are equal do you look at the next bit down, and so on. For 2-bit numbers A1A0 and B1B0:

G =

The first term says "A wins on the top bit". The second says "the top bits tie, and A wins on the low bit". L is the same with A and B swapped, and E comes from the equality comparator.

Two handy shortcuts:

  • Since exactly one output is 1, L = .
  • A ≥ B is G + E, which is also just .

Larger comparators repeat the pattern bit by bit, or are chained from 4-bit blocks that pass their results down. An ALU can also compare by subtracting and checking its status flags.

GEL
0000010
0001001
0010001
0011001
0100100
0101010
0110001
0111001
1000100
1001100
1010010
1011001
1100100
1101100
1110100
1111010

Worked examples

Example

Using the 2-bit G equation

Check G = on two cases.

  1. 1.

    A = 11 (3), B = 10 (2): = 1 · 0 = 0. Top bits tie, so the second term is = 1 · 1 = 1. G = 1. ✓ 3 > 2.

  2. 2.

    A = 01 (1), B = 10 (2): = 0 · 0 = 0. Top bits differ, so the second term is 0. G = 0. ✓ 1 < 2.

  3. 3.

    In the second case L = = 1 · 1 = 1: B wins on the top bit.

Example

Comparing 4-bit numbers by hand

A = 0111 (7), B = 1000 (8).

  1. 1.

    Bit 3: A has 0, B has 1. They differ, so this bit decides.

  2. 2.

    B has the 1, so A < B: L = 1, G = 0, E = 0.

  3. 3.

    A has more 1s overall, but that doesn't matter: one higher bit outweighs all the lower ones together.

Common mistakes

  • Writing G = . For 01 vs 10 the second term is 1, claiming 1 > 2. The low bits may only decide when the high bits tie.

  • Comparing from the LSB, or counting 1s. Only the highest differing position matters.

  • Using these unsigned rules on two's complement numbers. With signed numbers, a 1 in the sign bit means negative, so the rule changes.

Practice Magnitude comparator

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Magnitude comparator is taught in Combinational Logic.