# Comparator using Logic Gates only

How might a comparator with only logic gates look like? Isit like:

• What are you comporting for equality or x >y or x < y? – Dean Nov 13 '11 at 3:02
• I comparing for equality here. Isit possible to compare < or > whith only logic gates? Meaning not an ALU subtract? – Jiew Meng Nov 13 '11 at 3:06
• – Dean Nov 13 '11 at 3:26
• I think you could just post an answer with the link and some quotes from the site then I could just accept it? – Jiew Meng Nov 13 '11 at 4:00
• @jiewmeng, everything an ALU does is made up of logic gates, everything a computer does on that note, minus the addition of RAM, but flip-flops often form the backbone of the processor itself, at least in my basic level of design classes I took years ago. All math functions are implemented with logic gates, even subtract, add, multiply and division. In lower cost systems the last two are often implemented using the previous two and quite a few clock cycles, but it can be done directly. – Kortuk Nov 13 '11 at 4:50

## 1 Answer

Your answer looks fine as is (assuming an XOR is counted as a logic gate (and I can't see why not).

You can reduce gate count by one by using an 8 input NAND or AND at the output. eg 74xx30 8 input NAND.

If your XOR gates were open collector you could connect all their outputs, add one resistor and remove the AND gates. Depends wheher your rules allow a resistor pullup with an open collector gate.

• Hmm I haven’t learnt that I could use a resistor here. But the limitation I am given (in the exam question) was max of 4 fan into gates – Jiew Meng Nov 13 '11 at 4:53