# How could I 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?

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’

• An 8:1 multiplexer has 11 inputs, not 3: There are 8 "signal" inputs and 3 "select" inputs. I haven't worked out a solution to the problem, but it's not true that there are insufficient inputs on the 8:1 mux to allow for the 4 inputs needed in your problem. – The Photon Feb 21 '15 at 0:05
• This sounds like a homework question, so we won't give you a direct answer, but we'll help you get started if you can show us what you have worked out so far. For example, can you show us your truth table for this problem? – Dave Tweed Feb 21 '15 at 0:10
• Besides using an 8:1 multiplexor (like the 74LS151 I assume), are there any other restrictions? Can you use more than one multiplexor? What about "glue" logic? AND and inverters? – tcrosley Feb 21 '15 at 1:09
• Start with a truth table. The answer may be pretty obvious from that. – alex.forencich Feb 21 '15 at 2:00
• Dave Tweed, I do have a truth table based roughly off a truth table the teacher provided, but his was three variables and this is four. Here is my truth table so far. I'm not sure if I'm in the right direction here: – Peter Griffin Feb 21 '15 at 2:02

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:

simulate this circuit – Schematic created using CircuitLab

• I've tried to implement this but I'm having problems. For one thing, shouldn't 6 be 1 and not 0? Also, there are many matches between A0 and the A >= B column, not just two. So far, I have four switches that are either on or off, and every combination of two bits that equal a larger or equal number than that of the other two bits (A >= B) should result in an output of 1. But I'm getting all kinds of inconsistencies with this. It appears to be random whether it's 1 or 0. – Peter Griffin Feb 21 '15 at 6:43
• I see where I screwed up. I didn't bunch it in pairs. I see where you got your values. It took me a while to figure out where you got everything. Thanks for the help. I will make you best answer. – Peter Griffin Feb 21 '15 at 17:59