# Constructing a logic circuit with a control line

I have a question about logic gates.

I am wondering how to construct a logic circuit that makes its outputs c and d equal to its inputs a and b when a control is set to 0. If the control is set to 1, the outputs are flipped. I have had trouble constructing the circuit. Should I use and and nor gates? I have looked at flip flop circuits and have tried to determine if they are similar, but I am not totally sure.

• I think your question got downvoted because 'the outputs are flipped' has at least two interpretations: either c = !a, d = !b, or c = b, d = a. Please specify which is yours. – Wouter van Ooijen Sep 26 '11 at 21:19
• c = b and d = a. Sorry about that. – John Sep 26 '11 at 21:51

Look up XOR gate. One way of thinking about a XOR gate is that it inverts or passes the value on one input as a function of the other input. Here is a simple truth table:

In 1  In 2    Out
----  ----   ----
0     0      0
0     1      1
1     0      1
1     1      0

Think about this a bit and you should be able to see how it can be used as a conditional invert. In your case you'll need two XOR gates since you have two signals to conditionally invert.

You might be at a point in your education where you're not allowed to use XOR gates. In that case, you're going to want to just construct a 4 column truth table. And simplify with K-Maps/Boolean algebra.

A B Control Out --- --- --- ---

c = a, d = b
c = b, d = a


A 'high level' way to do that would be two use two two-input multiplexers. Check http://en.wikipedia.org/wiki/Multiplexer

Wouter calls it a "high level" approach, but a multiplexer is what you'll end up with in the end, no matter whether you pick one as a logic block, or construct your own from gates. A 2-to-1 multiplexer lets you choose which one of two inputs is switched to the output. This is the schematic of a 74AUP1G157: If $S = 0$ then $Y = I_0$ else $Y = I_1$. So connect $A$ to $I_0$ and $B$ to $I_1$ on one multiplexer, and $B$ to $I_0$ and $A$ to $I_1$ on the other one, and connect the select signals $S$ together.

Instead of two 74AUP1G157s you can also use a 74HC157, which contains 4 multiplexers.

• By 'high 'level' I meant that you can take two muxes and have your circuit, without even knowning what is in het mux. – Wouter van Ooijen Sep 27 '11 at 8:09
• @Wouter - Snap ik wel :-). Sorry if it doesn't show that way in my answer. – stevenvh Sep 27 '11 at 8:34
• no offence - you added the 'lower level' of understanding the guts of a mux. – Wouter van Ooijen Sep 27 '11 at 10:07

By "flipped", do you mean that when control=0, c=a and d=b, and when control=1, c=b and d=a? If so, I would suggest that you start by figuring out the c output in terms of control, a, and b. Then compute the d output similarly, but with the roles of the a and b inputs switched.

A conventional approach for computing c based on a and b would use one "or" gate, two "and" gates, and an inverter; a precisely equivalent circuit would use three "nand" gates and an inverter. The inverter computes the same signal when computing c as when computing d, and could thus serve both roles (so the total for computing both c and d would be six "nand" gates and one inverter).

An alternative approach would use three "xor" gates and one "and" gate. That requires fewer gates total, but the "xor" gates are generally twice as expensive in silicon as "nand" gates, so it's not really much of a "win".