Binary and addition
How Do Computers Add Numbers?
A computer first turns numbers into strings of 0s and 1s. A row of adding units then works from the lowest column up, each passing its carry to the column on its left. The resulting 0s and 1s are turned back into decimal for people to read.
Turning numbers into 0s and 1s
Each bit inside a computer has just two states, which match 1 and 0. So 5 is written 0101₂ and 3 is written 0011₂, just like showing them with four cards.
One adding unit per column
Each column is handled by a full adder. Its inputs are the column's two digits plus the carry from the right; its outputs are the column's sum and the carry sent left.
Connect four of these units side by side and you have a 4-bit adding machine. Connect eight and you have an 8-bit adding machine.
Walking through 5+3
For 0101₂ + 0011₂, start at the lowest column and pass every carry to the next column up.
- Lowest column: 1+1, S=0, C=1.
- Second column: 0+1 plus the carry 1, S=0, C=1.
- Third column: 1+0 plus the carry 1, S=0, C=1.
- Fourth column: 0+0 plus the carry 1, S=1, C=0.
- The result is 1000₂, which is 8 in decimal.
0101₂ + 0011₂ = 1000₂
| Place value | 8 | 4 | 2 | 1 |
|---|---|---|---|---|
| A | 0 | 1 | 0 | 1 |
| B | 0 | 0 | 1 | 1 |
| Carry in Cin | 1 | 1 | 1 | 0 |
| Sum S | 1 | 0 | 0 | 0 |
| Carry out Cout | 0 | 1 | 1 | 1 |
Carry: 8 ← 4 ← 2 ← 1
Why 8-bit inputs can give a 9-bit result
Each input to an 8-bit adding machine can be 0 to 255. Adding the two largest, 11111111₂ + 11111111₂ gives 111111110₂, which is 255+255=510.
The final carry needs a ninth bit, so the top carry is kept and the result can be up to nine bits. This is about unsigned whole numbers, without two's complement or signed overflow.
Where this model stops
This is a simplified whole-number adding model that shows column-by-column adding and passing carries. Modern CPUs use faster carry methods and more complex layouts, so they are not all a simple row of full adders.
Check yourself
In 5+3, which columns produce a carry?
Answer
The lowest three columns all carry. The fourth column receives a carry, writes 1 and does not carry, giving 1000₂.
How many bits can the sum of two 8-bit numbers need, and why?
Answer
Up to nine. The largest is 255+255=510, written 111111110₂, and the top carry takes the ninth bit.
What inputs does each column's adding unit need?
Answer
The column's two digits plus the carry from the column to its right.