The Overflow Reactor
What happens when the answer is too big for the bits?
Your mission
The reactor can only hold a fixed number of bits. Feed it two signed numbers, watch the adder carry from column to column, and find out what happens when the answer is too big, or too small, to fit. Then run six safety tests without a meltdown.
Explore
Add 6 + 3 with 4 bits, one column at a time, and see what the reactor does.
The reactor adds two signed numbers using a fixed number of bits, in two's complement. Let's add 6 + 3 using just 4 bits. Press Next column to add one column at a time, from right to left, and keep an eye on the warning light.
Add all 4 columns to continue.
Experiment
Change the numbers and the number of bits, and make all four reactor tests happen.
Reactor tests
Set A and B (tap the bits, or use − and +), then run the adder. Make each of these happen.
0 of 4 reactor tests done
Challenge
For each test, predict whether the reactor will overflow before it runs.
Complete all 6 safety tests to continue.
Understand
Here is what the reactor was showing you, in the words you need for the exam.
A fixed number of bits means a fixed range
In two's complement, n bits can store numbers from −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1.
- 4 bits: −8 to +7
- 8 bits: −128 to +127
Overflow happens when the true answer is outside that range, so the stored bits cannot show it.
How to spot overflow
- Two positive numbers give a negative result.
- Two negative numbers give a positive result.
- A positive plus a negative can never overflow.
Example: 95 + 48 in 8 bits gives 10001111, which reads as −113. The true answer, +143, is bigger than +127, so it overflows.
A carry out is not the same as overflow
When you add in two's complement, a carry out of the leftmost column is simply discarded. That alone does not mean overflow.
45 + (−18): 00101101 + 11101110 = 100011011. The carry falls off, and the stored result 00011011 = 27 is correct, because 27 fits in the range. Always check the true answer against the range, or use the sign rule above.
Words to know
- Carry
- When a column adds up to 2 or 3, a 1 is carried into the next column to the left.
- Carry out
- A carry from the leftmost column. In two's complement it is discarded.
- Range
- The smallest to largest value a number of bits can store.
- Overflow
- When the true result of a calculation is outside the range, so the stored bits are wrong.
Exam tip
When asked "does overflow occur?", show three things: the binary addition (with any carry discarded), the stored result read as a signed number, and the true answer compared with the range. Two patterns can look identical, like 1001 from 6 + 3 and from (−4) + (−3), but only one of them overflows.