Electronic – How to go about building a 2-bit comparator that compares two 2-bit numbers and determines whether one is greater than or equal to the other

comparatormultiplexer

Using an 8:1 multiplexer, I understand there are three inputs, so I'm not sure how I'd go about getting two 2-bit numbers, which would be four variables, not three. Any pointers on how to get started on this are appreciated.

A   B   C   D   X   Y   Z   X   Y   Z
0   0   0   0   0   0   0   0   0   D
0   0   0   1   0   0   1           
0   0   1   0   0   1   0   0   1   D
0   0   1   1   0   1   1           
0   1   0   0   0   0   1   0   D   D’
0   1   0   1   0   1   0           
0   1   1   0   0   1   1   D   D’  D’
0   1   1   1   1   0   0           
1   0   0   0   0   1   0   0   1   D
1   0   0   1   0   1   1           
1   0   1   0   1   0   0   1   0   D
1   0   1   1   1   0   1           
1   1   0   0   0   1   1   D   D’  D’

Best Answer

I think you understand the general approach, and since the "trick" required to answer this is rather subtle, I'm going to go ahead and spell it out.

Given two 2-bit numbers A and B, represented by the bits A1 A0 and B1 B0, respectively, the truth table for A >= B looks like this:

B1 B0 A1   A0     A >= B

 0  0  0    0       1
 0  0  0    1       1

 0  0  1    0       1
 0  0  1    1       1

 0  1  0    0       0
 0  1  0    1       1

 0  1  1    0       1
 0  1  1    1       1

 1  0  0    0       0
 1  0  0    1       0

 1  0  1    0       1
 1  0  1    1       1

 1  1  0    0       0
 1  1  0    1       0

 1  1  1    0       0
 1  1  1    1       1

I've deliberately grouped the rows in pairs, and I've put some extra space before the column for A0. Note that in each of the 8 groups, the answer is either always 0, always 1, or — in two cases — it exactly matches the A0 input.

This means that you need no logic other than your 8:1 multiplexer, connecting B1, B0, and A1 to the select inputs, and then wiring the 8 data inputs to 0, 1, or A0 as appropriate:

schematic

simulate this circuit – Schematic created using CircuitLab