digiwleeaLearn
Open the lab →

When logic starts to count

The moment gates do math

3 min read

Adding two bits is nothing more than an XOR gate for the sum and an AND gate for the carry, which is the moment logic gates stop being abstract truth functions and start performing arithmetic.

Builds onXORAND
You have built the gates as truth functions: XOR outputs 1 when its inputs differ, AND outputs 1 when both are 1. They have felt like logic, not math. This short bridge shows that those exact two gates, unchanged, *are* a one-bit adder. Nothing new is built here; you simply notice that arithmetic was already sitting in the gates.
The jump that feels big: logic seems to be about *true and false*, while arithmetic is about *numbers*. How does a gate that answers a yes/no question suddenly add? The answer is that adding two single bits produces a two-bit result, and each of those two output bits is itself a simple yes/no question about the inputs, exactly the kind of question a gate already answers.
Add two bits A and B. The possible sums are 0, 1, or 2, which in binary are 00, 01, 10. So the result has a sum bit (the ones place) and a carry bit (the twos place). Now ask the two yes/no questions:
  1. **When is the sum bit 1?** Exactly when one input is 1 and the other is 0, that is, when they differ. That is XOR: sum = A XOR B.
  2. **When is the carry bit 1?** Exactly when both inputs are 1 (only 1 + 1 reaches two). That is AND: carry = A AND B.
ABcarrysum
0000
0101
1001
1110
The carry column is exactly AND; the sum column is exactly XOR. Two gates you already have compute the full one-bit addition.
Look at the two output columns. The carry column is 0, 0, 0, 1, the AND truth table. The sum column is 0, 1, 1, 0, the XOR truth table. So 1 + 1 = 10 is not a special new operation, it is an AND gate saying "carry" and an XOR gate saying "sum is zero". Logic was doing arithmetic all along; you just had not read the columns as numbers yet.
Do not reach for OR when you mean XOR. OR outputs 1 on the 1 + 1 row too, which would make the sum bit wrong (it should be 0 there, with the 1 going to the carry). The sum bit is XOR precisely because it must go *back* to 0 once the column overflows into a carry.
Try it
Using only the rule "sum = A XOR B, carry = A AND B", compute the two-bit result of 1 + 1, then of 1 + 0.

Frequently asked

How do you add two bits with logic gates?

Use one XOR gate for the sum bit and one AND gate for the carry bit. sum = A XOR B and carry = A AND B. Those two gates together compute the complete addition of two single bits.

Why is the sum bit XOR and not OR?

Because when both inputs are 1 the sum bit must be 0 (the result 2 is 10 in binary, with the 1 going to the carry). XOR is 0 on that row; OR is wrongly 1. XOR is the function that returns to 0 once a column overflows.

When do logic gates become arithmetic?

As soon as you read their output columns as the bits of a number. Adding two bits is XOR for the sum and AND for the carry, so the same gates that answer true/false questions also add.
Those two gates side by side are the half adder. Next you will give it a carry-in and chain copies to add whole multi-bit numbers.

Every lesson here builds toward one thing: a working CPU, from the transistor up.

Open the free lab →
Found this useful? Share itShare on X