How can a computer add 1 and 1 if every logic gate outputs only 0 or 1?
A computer adds one and one and gets two. Yet each logic gate can send out only a zero or a one. How can two gates work together to give you the right answer?
Read across each row to see what the gates do with the same two inputs. XOR gives one when the inputs differ. AND gives one when both inputs are one. So the last row gives zero for XOR and one for AND.
A and B are both one, so AND gives one on the wire labelled X. Follow X into XOR. D is zero, so XOR receives different inputs and gives one on Q. This is a combinational circuit: its output depends only on the current inputs.
In that circuit, A, B and D are all one. Work out X from the AND gate first. Then follow X into the XOR gate with D. Pick the pair that gives X and Q.
Follow A as its wire branches to both gates. Now follow B as it branches to both gates too. XOR gives the sum bit, S, and AND gives the carry bit, C. Neither gate feeds the other. Together they make a half adder, which adds two bits with no carry input.
Set A and B to one. One XOR one gives a sum bit of zero. One AND one gives a carry bit of one. Write the carry on the left: one zero in binary means one two and zero ones, so the answer is two.
Now set A to zero and B to one. Work out the XOR and AND outputs separately. Then put the carry on the left and the sum on the right. Pick the two bits in that order.
Set A and B to zero and D to one. Follow the wires: AND gives X as zero, then XOR gives Q as one. If you start with XOR just because it's listed first, you get zero at the end. You've swapped the gates and evaluated a different circuit.
An exam question can ask you to complete the truth table for the logic circuit shown. Fill in both outputs on each row. Zero plus zero gives two zeros. Each mixed pair gives sum one and carry zero. Two ones give sum zero and carry one.