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 value8421
A0101
B0011
Carry in Cin1110
Sum S1000
Carry out Cout0111

Carry: 8 ← 4 ← 2 ← 1

Four adding units from right to left take 0101₂ and 0011₂. The first three columns each write 0 and carry left; the fourth receives the carry and writes 1, giving 1000₂, which is decimal 8.

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

  1. 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₂.

  2. 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.

  3. What inputs does each column's adding unit need?

    Answer

    The column's two digits plus the carry from the column to its right.