# How to make a digital comparator with multiple inputs?

I have been attempting to make a digital comparator but I am struggling to get in more than one input. The idea is that I have 2 sets of 2 numbers (4 inputs total) and I want to have the output take all 4 numbers into account rather than just 2. Here is what I roughly have so far: What I want the circuit to do is have the two inputs in the two sets treated as separately. Any ideas on how to achieve this would be very welcome.

• What outputs are you looking for? I assume A=B=C=D. But what about the < and > outputs? What do those mean for 4 inputs? Nov 1, 2014 at 23:36
• 74HC85? Nov 1, 2014 at 23:37
• I want the circuit to compare the two sets of numbers an then either output A < B , A = B or A > B . For example if a = 1 , b = 1, c = 1 and d = 0 the circuit should output A >B because the sum of A is bigger than B Nov 1, 2014 at 23:40
• Not sure of the question, but maybe sum the voltages in analog and then comparator(s) after that? How many outputs do you want? Nov 2, 2014 at 4:21

The starting point for a problem like this is to draw out a truth table of the logic that you intend to have the circuit synthesize. Your intention is still somewhat vague even after the comments.

If we guess that the input pairs c:d and b:a are actually representing two 2-bit binary numbers then the following truth table shows the output for when c:d == b:a. You can then add additional output columns to the table to represent the other outputs you may desire.

This should get you started. I won't present the whole final solution because you learn little from that. The mechanics for reducing the table shown for one output can be done following one of a number of known procedures including Karnaugh Maps.

In digital design, you very rarely will connect multiple gates to a single wire or node (as you have done with a,b and c,d). This is because otherwise if one gate is trying to pass a '1' and the other a '0', there will be a fight between the gates which is usually a power->ground short (creating a lot of heat, an indeterminate logic level, and probably breaking some component).

The exceptions for this would be logic gates which will always produce the same output (same gate with same inputs, or something less common) or if the previous gates can enter what is called a 'high-impedance state' (tri-state inverter, transmission gate, pass-gate, or dynamic gates) to allow only a single gate to pass it's output to the node at a time.

Your description is very ambiguous. It sounds like you want to compare two numbers, X and Y.

X = 0,1,2


and

Y = 0,1,2


where

X = A + B (A/B = 0,1)


and

Y = C + D (C/D = 0,1)

If X > Y, O1 = 1, O2=O3=0.  If X = Y, O2 = 1, O1=O3=0.  If X < Y, O3 = 1, O1=O2=0


What is not clear to me is whether you want to treat AB and CD as digital numbers representing 4 distinct values(0,1,2,3), or as two separate bits representing 3 distinct values (0,1,2). I will assume as separate bits representing (0,1,2).

In this case, create a truth table:

A B C D    O1  O2   O3
0 0 0 0     0   1    0
0 0 0 1     0   0    1
0 0 1 0     0   0    1
0 0 1 1     0   0    1
0 1 0 0     1   0    0
0 1 0 1     0   1    0
0 1 1 0     0   1    0
0 1 1 1     0   0    1
1 0 0 0     1   0    0
1 0 0 1     0   1    0
1 0 1 0     0   1    0
1 0 1 1     0   0    1
1 1 0 0     1   0    0
1 1 0 1     1   0    0
1 1 1 0     1   0    0
1 1 1 1     0   1    0


Now take each output individually and create a Karnaugh map. If you have any terms show up in multiple outputs, you can save logic gates and re-use the logic! Or, use a online Karnaugh map calculator: karnaugh-auto

$O1 = B\mathbf{\overline{C}\overline{D}} + A\mathbf{\overline{C}\overline{D}} + AB\overline{C} + AB\overline{D}$ $O2 = \overline{B}\mathbf{\overline{C}\overline{D}} + A\overline{B}\overline{C} + \overline{A}B\overline{C}D + \overline{A}BC\overline{D} + ABCD$ $O3 = \overline{A}\overline{B}D + \overline{A}\overline{B}C + \overline{A}CD + \overline{B}CD$

Where variables which touch means 'AND'; '+' means 'OR'; the $$\overline{Bar}$$ means inverse the variable. I bolded one like term that could be reused, I am sure you can find a lot more.

You don't have to find O2 that way, you can just do a NOR as you showed in your initial attempts on O1 and O3. Which if you worked out should be the same:

$O2 = \overline{(O1 + O3)}$