# Combinational circuit to check if two four bit numbers are equal

Right now, I've got:

(x1 and y1) (x2 and y2) (x3 and y3) (x4 and y4)

So the outputs from these gates will give me 1 when the bits from both numbers are the same. The issue here is that I will get positive results when they are the same and when each bit is different from each other bit (because 0,0 will still give a 1 in an and gate).

I'm probably missing something very obvious here. Thanks

• That has to be homework. Mar 1, 2011 at 2:44

4 x Xor gate... and 4 input nor gate

Xor each pair of inputs then use a 4 input nor gate...

Xor gate gives 0 when both inputs are the same.

a 4 input nor gate gives a logic 1 if all inputs are 0, and 0 if any input is 1.

or

Not((X1 XOR Y1) OR (X2 XOR Y2) OR (X3 XOR Y3) OR (X4 XOR Y4))

• Alternatively: ((X1 XNOR Y1) AND (X2 XNOR Y2) AND (X3 XNOR Y3) AND (X4 XNOR Y4)) Feb 28, 2011 at 23:38

"0,0 will still give a 1 in an AND gate". No, it won't. Are you using four 2-input AND gates feeding a 4-input AND? That will only be true when all of the inputs are true (1).

Testing for equivalence needs more than AND. To test A==B, you need to do A AND B OR NOT A AND NOT B, typically written AB + A'B'. This is called an XNOR gate (*), i.e. eXlusive N(egative)OR. In your case you just need to AND together the output from 4 XNOR gates.

(*) I think exclusive NOR is a bad name. It would be better to call it an inclusive AND. That would help with mixed logic design in which you start with all positive logic and slashes for complements. I grabbed this image from a paper on this subject by Mohamad Adnan Al-Alaoui:

Inclusive AND: (A + B') * (A' + B) = (A * B) + (A' * B')
Exclusive  OR: (A * B') + (A' * B) = (A + B) * (A' + B')


Edit: The inclusive AND includes the case in which they're both false, and the exclusive OR excludes the case in which they're both true. Much confusion arises when one isn't clear about the exclusivity of a condition. Someone will ask if it's "A or B" (OR) but really mean to ask if it's "Either A or B, but not both" (XOR). Also, I think in this case the question was using AND in an inclusive sense to mean equivalence.