seegongsik
Saved words
Structure

Chain gates and you get an adding machine

The and, or, not gates we built last time. Chain a few of them and, amazingly, they become a machine that adds. This is the very starting point of how a computer calculates.

01

In the world of 0s and 1s, 1+1 is 10

Before building addition as a circuit,
let's first see how to add with 0s and 1s.
0+0 is 0,
0+1 is 1.
Easy so far.
But 1+1?
There's no 2,
so it carries up and becomes 10.
Not ten in decimal,
but one-zero in binary.

¹
1
+ 1
10
No 2, so it carries up to 10 (one-zero in binary)

Try adding two bits.

So adding two bits
gives two results.
One is the value that stays in this place,
one is the value passed to the next place.
These two are called
the sum and the carry.

02

The sum is XOR, the carry is AND

Here's the amazing part.
That rule you just saw
is built exactly from last time's gates.
The sum is 1 only when the two differ, right?
That's XOR (being different).
The carry is 1 only when both are 1, right?
That's AND.
Two gates and you're done.

A
0
B
0
Half adder
Carry (AND)
0
Sum (XOR)
0
Sum = A XOR B  ·  Carry = A AND B
0 + 0 = 00 (Carry 0, Sum 0)

Half adder. Toggle the inputs.

This little machine,
which adds two bits
and puts out a sum and a carry,
is called a half adder.
With just two gates,
we've built the simplest adder
in the world.

03

Real addition adds the incoming carry too

But the half adder has a gap.
When adding several places,
the carry coming up from the place below
has to be added in too.
So there are three inputs.
A, B,
and the carry received from below.
Adding all of these is the full adder.

A
0
B
0
Carry in
0
Full adder
Carry out
0
Sum
0
0 + 0 + 0 = 00

Full adder. Three inputs.

A full adder is really
two half adders joined together.
Make a slightly bigger part from small parts,
then chain that again
to make something bigger still.
This is how computers are built.

04

Chain several and you add big numbers too

One full adder
adds just one place.
So what about four-digit, eight-digit numbers?
Simple.
Just chain full adders side by side.
Passing each place's carry
into the input of the place next to it.
Try adding two numbers yourself.

A
0
0
0
0
0
+ B
0
0
0
0
0
Sum
0
0
0
0
0
0
0 + 0 = 0

Toggle two numbers and add them (4-bit).

Turn on the top row and the middle row,
and the sum appears on its own in the bottom row.
It isn't a person calculating,
it's the gates passing the carry sideways,
making the answer by themselves.

05

Addition was gates all along

A computer doing calculation
wasn't magic after all.
It's just the and, or, not gates,
chained into a fixed shape.
Flip the switches,
and electricity flows through the gates
until the answer lights up.

Gates (and, or, not)
chain two
Half adder (one-place addition)
chain two
Full adder (with carry)
chain several
Addition of big numbers

From small to big.

This is how big functions
grow from small parts.
Next time we'll meet a circuit
that holds onto a value
even while electricity flows through,
that is, a circuit that remembers.

In one lineWe solved the carry of 1+1 with two gates, and chained them to build the addition of big numbers. A computer's calculation wasn't magic, but gates cleverly chained together.
Was this helpful? Support seegongsik
Structure