Electronics
How to add binary numbers
To add binary numbers, work column by column from the right, exactly as in decimal, but carry as soon as a column reaches two. There are only four rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1), and 1 + 1 + 1 = 11 (write 1, carry 1).
A worked example
Add 0110 (6) and 0011 (3), starting at the 1s column:
| Column | 8s | 4s | 2s | 1s |
|---|---|---|---|---|
| Carry in | 1 | 1 | 0 | |
| A | 0 | 1 | 1 | 0 |
| B | 0 | 0 | 1 | 1 |
| Sum | 1 | 0 | 0 | 1 |
- 1s: 0 + 1 = 1, no carry
- 2s: 1 + 1 = 10, write 0, carry 1
- 4s: 1 + 0 + the carry = 10, write 0, carry 1
- 8s: 0 + 0 + the carry = 1
The answer is 1001: 8 + 1 = 9, and 6 + 3 is 9. Each carry moves one place left, worth twice the column it came from.
Live experiment
Watch the carries ripple
Two 4-bit numbers, A and B, one tile per bit: tap a tile to flip it. The sum underneath is worked out column by column, and each carry hops into the next column. Make a carry ripple through three columns, then a sum too big for four bits.
“Adders” is lesson 4 of 6 in Logic Grid, Electronics World 7. Free with an account. Lessons unlock in order, so you’ll do the 45 before it first.
Overflow
Four bits hold 0 to 15. Add 1011 (11) and 0111 (7) and the true answer, 18, is 10010: five bits. A 4-bit adder has nowhere to put the top carry, so it keeps only 0010, which reads as 2. That lost carry is overflow.
Old arcade scores rolled back to zero for exactly this reason. Processors keep the lost carry in a carry flag, so a program can notice it, or chain two additions to handle numbers wider than the adder.
How hardware does it
Each column is a small circuit. The sum bit is 1 when an odd number of its inputs are 1, which is XOR. The carry is 1 when two or more are 1. A circuit for one column with a carry coming in is a full adder; chain one per bit, each carry out feeding the next carry in, and you have a ripple-carry adder. The first column has no carry in, so it can be a simpler half adder: one XOR and one AND.
Check your answer
Convert both numbers and the sum to decimal and compare. 1011 + 0101: 11 + 5 = 16, which is 10000, so in four bits it overflows to 0000. If your sum ever has a 2 in it, you forgot to carry.
Free lesson
Now build it yourself
Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.
“Adders” is lesson 4 of 6 in Logic Grid, Electronics World 7. Free with an account. Lessons unlock in order, so you’ll do the 45 before it first.
Or start from the very first lesson, no account neededWork it out
Practice questions
Three quick questions from the lessons. Pick an answer to check it.
Show the answer
Answer: 0 and carries 1. Binary has only the digits 0 and 1, so two is written 10. The column keeps the 0 and carries the 1 to the next column, just as 9 + 1 does in decimal.
- Why not “1 and carries 1”? 1 with a carry is 11, which is three. Two 1s make two, 10, so the column keeps 0.
- Why not “2”? Binary has only the digits 0 and 1, so a column can't hold a 2. Two is written 10: a 0 here and a 1 carried.
Show the answer
Answer: SUM is XOR, CARRY is AND. The sum bit is 1 for 0 + 1 and 1 + 0, and 0 for 0 + 0 and 1 + 1: exactly XOR's table. The carry is 1 only for 1 + 1: exactly AND's.
- Why not “SUM is OR, CARRY is AND”? OR gives 1 for 1 + 1, but the sum bit there is 0. Only XOR's table matches the sum column.
- Why not “SUM is AND, CARRY is XOR”? That's backwards: AND is 1 only for 1 + 1, which is the carry, and XOR is 1 for 0 + 1 and 1 + 0, which is the sum.
- Why not “Both are XOR”? An XOR carry would be 1 for 0 + 1, which never carries. The carry is 1 only for 1 + 1, which is AND's table.
Show the answer
Answer: 3. 1 + 2 = 3.
- Why not “1”? 1 counts only the 1s wire. The 2s wire is on too, adding 2 more.
- Why not “6”? 6 would be the 4s and 2s wires. With the 1s and 2s on, the value is 1 + 2.
- Why not “12”? 12 is the 8s and 4s together, the two wires that are off here.
“Adders” is lesson 4 of 6 in Logic Grid, Electronics World 7. Free with an account. Lessons unlock in order, so you’ll do the 45 before it first.
Questions people ask
What is 1 + 1 in binary?
10, which is two. Binary has only the digits 0 and 1, so a column holding two writes 0 and carries 1 into the next column, just as 9 + 1 in decimal writes 0 and carries 1.
What is overflow in binary addition?
A sum too big for the number of bits. Four bits hold 0 to 15, so 9 + 8 = 17 needs a fifth bit; the carry out of the top column is lost and only 0001 remains. Processors keep that lost carry in a carry flag.
How do computers subtract in binary?
They add the two's complement: flip every bit of the number being taken away, add 1, then add as usual and drop the carry out of the top. 7 − 2 becomes 0111 + 1110 = 1 0101, and the four bits left, 0101, are 5.
Related topics
- Half adder vs full adderA half adder adds two bits; a full adder adds the carry too, so they chain.
- Binary numbers explainedPlaces worth 1, 2, 4 and 8: add up the bits that are on, and four wires count to 15.
- What is an ALU, and how does it work?Work out every answer at once, then let the opcode pick one: the heart of a CPU.
- What is an XOR gate?1 when the inputs differ, 0 when they match: the gate behind stair lights, adders and parity bits.