Module 5 · Adding With Light Switches

What happens when the answer needs more switches than you have?

Lesson 5.3 · Too Big to Fit

Mark · Rob · Jenny

9 + 8 = 1? Kind of.

Mark tries to break the adder.

He sets 9 and 8. The four sum lights show 0001, and a fifth light, the last carry, glows off the end.

Mark says the machine thinks 9 plus 8 is 1. Rob says that’s the bug that ended Pac-Man.

The short answer

The last carry falls off the end and the number wraps around. 9 + 8 is 17, which is 10001, and with four switches you only keep the 0001. It’s why counters have ceilings, why Pac-Man has a broken level, and why programmers have to check.

Try it yourself

Set these and watch the last carry. Four switches can only hold up to 15.

Set 9 + 8

1 of 2

First number

Second number

Carry

Off
Off
Off
Off

Sum

Off
Off
Off
Off
Off

0 + 0 = 0

What you just did has a name

Overflow

Overflow is what happens when a result is too big for the number of bits set aside to hold it.

The last carry falls off the end and the number wraps back around to something small.

Computers have a one-bit warning light, called a flag, that notices it, but if the program doesn’t check, the wrong number carries on as if nothing happened.

A few more things

Pac-Man’s level 256

The original Pac-Man counted levels with 8 bits, so it could count to 255. On level 256, the math that draws the fruit at the bottom overflowed and filled half the screen with garbage. Nobody could finish it.

The video that almost broke a counter

In 2014 Gangnam Style got close to 2,147,483,647 views, the biggest number a 32-bit counter can hold. YouTube’s engineers saw it coming and had already moved to a 64-bit counter. Then they joked that PSY broke it.

Why more bits help

A 64-bit number can count past 18 quintillion. Overflow still exists, it’s just a lot harder to reach.

Go deeper

The longer version, if you want it.

The year 2038

Many computers count time as seconds since January 1, 1970, stored in a 32-bit number. That number overflows on January 19, 2038. Old systems that still use it will think it’s 1901.

Most modern systems have already moved to 64-bit time, which won’t overflow for billions of years. But it’s the same lesson as Pac-Man: every number in a computer has a ceiling, and someone has to plan for it.

Quick check

An 8-bit counter is at 255 and goes up by one. With no overflow check, what does it show?

Let’s take it slower

Picture an old car odometer that only has four wheels, so it tops out at 9,999 miles. Drive one more mile and every wheel rolls over to 0000. The car didn’t lose the miles. The odometer just ran out of wheels. Overflow is a computer running out of wheels.

More examples

1

The arcade high score

Some old arcade games stored scores in too few digits. Great players looped the score back to zero, which was either a triumph or a tragedy depending on who saw it.

2

The 4 GB file limit

Some USB sticks can’t hold a file bigger than 4 GB because the format stores each file’s size in 32 bits. This module’s Fix-It Card is about that one.

Back to the question

So what happens when the answer is too big?

Show the answer

The last carry falls off the end and the number wraps around. 9 + 8 is 17, which is 10001, and with four switches you only keep the 0001. It’s why counters have ceilings, why Pac-Man has a broken level, and why programmers have to check.

One last question

Which of these would you trust?

“Overflow happens when a result needs more bits than it has room for.”

“Computers can never get arithmetic wrong.”

“Using more bits per number makes overflow much rarer.”

“Overflow only happened in old games.”

Talk Card

Talk Card · 5.3

Every number in a computer has a ceiling. Go past it and it wraps back around, which is how Pac-Man broke at level 256.

How Computers Work · pettigrewlab.com/learn

Next lesson