◈ computers mapVol 1 · Ch 05/19
How Computers Work from the transistor up · chapter 05

05Negative Numbers

Chapter 4 taught us to count in two symbols, and every number we wrote came out positive — a tidy sum of powers of two. But look inside a real machine for a minus sign and you won't find one. There's no “” key wired into the silicon. There's no third symbol hiding behind the 0 and the 1. So a computer that needs to represent −5 has the same alphabet it had for +5: two symbols, nothing more. That forces a strange and wonderful question. If a sign isn't a symbol you can write, then flipping a number's sign has to be an arithmetic operation on the bits themselves. What operation turns +5 into −5? Here's the part that makes this one of the most elegant ideas in the whole machine. We're going to answer it so cleverly that the adder we build next chapter can add a positive and a negative number with the identical circuitry it uses for two positives. It never even learns that negatives exist. We'll get there in small, honest steps. First we'll watch the obvious idea fail — stealing a bit to mean “minus.” Then we'll fix it with a single reinterpretation, bend the number line into a circle, learn to negate any value by hand, and pin down the exact range and where it overflows. Finally we cash in the prize: subtraction, for free. No magic — just arithmetic that wraps around, exactly the way a clock does.

01There is no minus key

Let's start from what we already trust. In Chapter 4 a run of bits meant a plain, unsigned number. Each column is a power of two, and the value is the sum of the columns that are switched on. We'll spend this whole chapter in a small, four-bit world — four wires, wide enough to see everything and narrow enough to fit on a page. So here is that four-bit reader again. Flip the bits and confirm the reflex from last chapter: 1011 is 8 + 2 + 1 = 11, and every pattern lands somewhere from 0 to 15.

decimal total 11 11 of 15
1011₂ = 11
Each place is worth twice the one to its right: 8, 4, 2, 1. Click a bit to flip it, and read off only the places that are on.
Fig 1. The number 1011 in binary isn't eleven separate things — it's a set of switches, each guarding a place worth double the last: 8, 4, 2, 1. Read only the places that are on (8 + 2 + 1) and you get 11. Flip any bit and watch its term light up and the total climb. A bit is exactly this: one binary digit, one switch, one place.

Now notice the cage we're actually in, because it's the constraint the whole solution has to respect. Four wires give you exactly 2⁴ = 16 distinct patterns — not one more. That's a fixed budget, the thing engineers call fixed bit-width: n wires, n bits, exactly 2ⁿ patterns, forever. Right now all 16 of those slots are spent on the non-negative numbers 0 through 15. If we want negatives, we can't ask for extra patterns — there aren't any. We have to re-assign slots we already own. Widen and narrow the word below and watch the budget of patterns double and halve. That ceiling is what we now have to share between positive and negative.

WORD WIDTH — 8 WIRES a byte every wire = 1  ·  place values double leftward  ·  all‑ones is the maximum the ceiling doubles with every wire you add → 2⁸ = 256 highest value it can hold 255 the range is 0 … 255 distinct values  (2ⁿ) 256 2⁸ patterns of 0s and 1s
the top wire alone is worth 128 — more than every wire below it combined (127). That is why one more wire doubles the range.
8 wires — a byte · 256 states · counts 0 … 255
Fig 2. A word is just a chosen number of wires read together. Widen it — drag the slider, tap , or jump to a nibble (4), a byte (8), or a full 16‑bit word — and watch the ceiling climb 1, 3, 7, 15 … 255 … 65,535. The pattern is exact: n wires give exactly 2ⁿ distinct values, so the range is always 0 … 2ⁿ−1. And each wire you add is worth more than everything beneath it combined — which is why one more wire always doubles the highest number the word can hold.

One more piece of bookkeeping before we try anything clever, because it trips people up later. A machine's wires are physical and fixed. So a small number doesn't come with a short bit pattern — it comes padded. In a four-bit slot, 5 isn't 101; it's 0101, with a leading zero filling the unused top column. And when you add two numbers, both sit in the same fixed width, their columns lined up dead straight. Set a value below and watch it snap to the full width. Those leading zeros are not decoration — they're the top wire honestly reading 0 volts.

the register · fixed physical wires — every column is a real conductor leading zeros 0 = 0V (tied to ground)  ·  1 = 5V (high)
one leading zero
the top wires don't vanish when the number is small — they stay, honestly reading 0. That's why 5 is 0101, not 101: the width is fixed by the metal, and the number pads up to fill it.
Fig 3. A register is a fixed row of physical wires — you can't have "three and a half" of them. Drag value and watch the number snap into the whole width: the low wires carry the bits, and the unused top wires don't disappear, they sit at 0V and honestly read 0. Those are the leading zeros (the gold-bracketed columns) — real conductors, just padding. That's why 5 is 0101 in a 4-bit register, not 101. Flip to 8-bit and the same 5 becomes 0000 0101: more wires, more leading zeros, identical number. Fix the width and every value lines up in the same columns — which is exactly what lets two of them add, bit against matching bit.

So here's the first thing anyone tries, and it's a reasonable instinct. We have a spare top bit just sitting there — why not make it a sign flag? Let the highest bit mean “this number is negative,” and let the remaining three bits carry the size. This is a real, named scheme — sign-magnitude — and for reading a number off, it works beautifully. 0101 is +5, and flip the flag to 1101 and you get −5. Try it below — it looks like we're done.

sign flag magnitude · 0–7 0 means + 1 4 0 2 1 1 +5 the value it claims 0 101 → + · magnitude 5 = +5 flip the sign flag and the same magnitude just reads negative
Click a cell to flip it. The top bit is a plain sign flag; the other three hold the size.
reads back perfectly ✓
Predict: is that really all it takes to get negatives — or is there a value this scheme can write two different ways?
The obvious first idea: steal the top bit and let it mean the sign — 0 for plus, 1 for minus — while the rest holds the size. Toggle the sign flag and 0101 becomes 1101, +5 becomes −5. Reading it back works every time, so it looks like the whole problem is solved. It very nearly is.

But watch it break the moment you ask it to do the one thing numbers are for. First, a small ugliness: there are now two zeros. 0000 is +0 and 1000 is −0 — two patterns wasted on the same nothing. The fatal problem is worse. Take +5 = 0101 and −5 = 1101 and add them the ordinary, column-by-column way a plain adder would, carries and all. You get 10010, which is emphatically not zero. The circuit would have to stop, read the sign flags, and switch to a completely different subtracting procedure. That's a whole second machine bolted on — exactly the expensive thing we're trying to avoid. Sign-magnitude fails not because it can't represent negatives, but because the adder can't stay dumb.

02Make the top bit negative

The fix is almost insultingly small, and it's the keystone of the entire chapter. But we don't choose it — the hardware chose first. Recall the counter from Chapter 4: when every column is full, adding one rolls the word over, so 1111 ticks to 0000 and the carry falls off the end. So what number, added to one, gives you zero? Minus one. So 1111 is already behaving like −1, before we pick anything. The machine isn't wrong. Our labels are. And we know exactly how wrong: 1111 reads 15, it must read −1, and 15 − 16 = −1. So every top-half pattern must lose exactly 16, one full lap, while every bottom-half pattern must not move a hair. Which single column is on for exactly the top-half patterns, and off for the rest? The top one — that is what the top bit is. It contributes +8, and we need 16 less: 8 − 16 = −8. We never picked −8. We were cornered into it. So the top bit isn't a flag meaning “negative”; it's an ordinary place value that simply is negative. The columns were +8, +4, +2, +1, and now they read −8, +4, +2, +1. That change is called two's complement, and the rest of this chapter falls out of it. Read 1011 with the new weights: −8 + 2 + 1 = −5. Toggle the bits below: the same four switches as Fig 1, but the top column now subtracts.

Now run the test that killed the last scheme, on the very same numbers. +5 is still 0101. But −5 is no longer 1101: under the new weights, the pattern that reads −5 is 1011, because −8 + 2 + 1 = −5. Add the two the ordinary, column-by-column way a dumb adder would, carries and all: 0101 + 1011 = 10000. Five bits came out of a four-bit box, so the top one falls off the end, exactly as it did when 1111 ticked to 0000. That stray bit is one full lap of sixteen, and a lap is worth nothing. The four wires read 0000. Zero. No stopping to read a sign flag, no branch, no second machine bolted on. That is the identical sum that murdered sign-magnitude, and the dumb adder just did it in its sleep.

−8 this column subtracts 1 −8 +4 adds 0 +0 +2 adds 1 +2 +1 adds 1 +1 the four bits 1011 plain place-value sum −8 + 2 + 1 −5
same four bits — read as unsigned = 11, but flip the top column's sign and it reads signed = −5
1011 → −8 + 2 + 1 = −5
Click a switch (or the presets). Nothing changed but the name of the top column: its place value went from +8 to −8. Plain place-value addition now lands on negatives — no special "sign flag" anywhere.
Fig 5. The keystone. Don't treat the top bit as a "minus flag" bolted on — just make its column worth −8 instead of +8. Now the four places read −8, +4, +2, +1, and the exact same place-value addition you already know suddenly names negatives: 1011 = −8 + 2 + 1 = −5. Toggle the switches and watch the signed total swing from −8 (only the negative column on) up to +7 (all the positive columns on). One reinterpretation of a single column — nothing else in the machine changes — and binary covers the whole number line.

Now sit with what fell out for free, because we never asked for any of it. There's still exactly one zero (0000) — no wasted twin, no −0. Positive numbers 0 to 7 keep the exact patterns they had in Chapter 4, so there's nothing to relearn. Not one wire changed either; all we changed is what we call the top column. And the negatives arrived on their own, in the order the counter was already counting them in. That order is worth watching once more, right at the top of the count: 1111 ticks back to 0000, carrying off the end. Watch that wrap happen one more time. It's the hinge the next idea swings on.

carry → 8 4 2 1 place value — each worth double its right neighbour 0 0 0 0 +1 enters here ↑ a 4-bit odometer, written in two symbols decimal 0 1
0000₂ = 0
Counting is just add one. When a column already shows 1 it can't go higher — it rolls back to 0 and carries the 1 to the column on its left. Jump to 0111, then press +1.
Fig 6. Counting has exactly one move: add one. In two symbols a column only holds 0 or 1, so when you add 1 to a column that's already at 1 it can't climb higher — it rolls over to 0 and passes a carry to the column on its left, exactly like 9→0 on a car odometer. Jump to 0111 and press +1: three columns top out and reset in a single tick while the fourth flips up — 0111 becomes 1000. Push it from 1111 and the carry runs clean off the end, wrapping back to 0000.

Here's the reframe that makes two's complement click. If counting up eventually wraps from the highest pattern back to 0000, then the number line isn't a line at all — it's a circle. Bend all sixteen patterns around a ring in counting order. Now the seam where 1111 meets 0000 stops being an accident and becomes the whole point: the pattern just below zero is 1111. And under our new weights, 1111 reads as −8+4+2+1 = −1. So −1 sits exactly where “one step back from zero” should sit. The negatives aren't scattered — they're the top half of the wheel, counting backward from the seam. Spin it and watch positive climb one way, negative climb the other, and the two meet at the bottom.

So ask the question your gut has been holding since the wheel appeared. Is 1111 fifteen, or is it minus one? Both. And the wires will never tell you which. There's no bit anywhere in this machine that records “this word is signed.” Those four wires are four voltages, sitting there, holding the same pattern they held in Chapter 4. 15 and −1 are two readings we lay over them, and both readings are correct. The pattern is the noun. Signed or unsigned is the verb, and the verb lives in the instruction that reads the bits, never in the bits themselves. That's why a real CPU carries a signed compare and an unsigned compare as two separate instructions over the identical wires. It's also why, a few pages from now, one single addition will answer two different questions about running out of room.

the seam ↴ 1111 → 0000 +1 ↻ ↺ −1 opposite 0 · +7 and −8 meet 4-bit wheel YOU LANDED ON = 0 0 signed value unsigned, this pattern is 0
Drag the wheel to spin the needle, or step one tick. The place-values under the bits do the reading: in signed mode the top bit is worth −8, so 1111 = −8+4+2+1 = −1.
0000 · the wheel’s zero
Fig 7. Counting can only wrap, so the number line is really a circle. Here are all sixteen 4-bit patterns bent into a ring: 0000 at the top, positives climbing clockwise to +7, and — crossing the seam where 1111 meets 0000 — the negatives counting backward down the other side. Spin the wheel or step one tick: the pattern one notch below zero is 1111, and it reads −1, not 15. The place-values give it away — flip the top bit’s weight to −8 and 1111 = −8+4+2+1 = −1. The two extremes, +7 and −8, meet at the bottom, directly opposite zero. Toggle to unsigned and the same ring reads 0…15 with no negatives at all — same bits, different reading.

Three landmarks on that wheel are worth memorizing, because you'll read them by reflex for the rest of your life as an engineer. 0000 is 0. 1111 — all ones — is −1 (every column on, the −8 outweighing all seven of the positives below it by exactly one). And 1000 — the top bit alone — is the most negative value there is, −8, with nothing to soften it. Notice the tell for sign that makes this scheme so cheap in hardware. The top bit is 1 for every negative number and 0 for every non-negative one. One wire, read directly, is the sign. Click through the landmarks below.

-8 +4 +2 +1 0 0 0 0 sign bit THE SIGN TELL — read one wire top bit = 0 → zero / positive 0 decimal value 0 two's complement · 4-bit
Three patterns worth memorising — or flip any bit yourself.
0000 → 0. The floor of the non-negatives.
Three patterns are worth burning into memory: 0000 = 0, 1111 = −1 (all ones is always minus one), and 1000 = −8 (the top bit alone is the most negative number a 4-bit word can hold). Flip any bit and watch the sum rebuild from its signed weights −8, +4, +2, +1. And notice the cheap tell: the leftmost wire is 1 for every negative and 0 for every value ≥ 0. One wire is the sign.

And none of this is special to four bits. The recipe generalizes exactly. In an eight-bit byte, the top column's weight flips to −128 while the rest stay +64, +32, … +1. That gives a signed range reaching from −128 up to +127. Same idea, wider wheel. Flip a full signed byte below and read the top bit as the sign it now carries.

a signed byte — top place now weighs −128, the rest +64…+1 SIGN BIT ↓ −128 +64 +32 +16 +8 +4 +2 +1 0 0 0 0 0 0 0 0 b7 b6 b5 b4 b3 b2 b1 b0 −128 −64 0 +64 +127 negative half positive half = −128 −128 the sign it carries negative
byte  10000000
= −128
top bit is 1 — so the byte is negative
Click any switch. Nothing new here — it's the 4-bit wheel widened to eight places. The top place just flipped its sign to −128, so the wheel now spans −128…+127, and the top bit alone tells you which half you're on.
Nothing special ever happened at four bits. Widen the wheel to eight and the same rule rides along: give the top place a negative weight — here −128 — leave the other seven at +64 down to +1, and a byte spans −128 to +127. Flip the switches: the top bit alone is the sign it carries — 1 lands you on the negative half, 0 on the positive. Same idea, wider wheel.

03Negate: invert and add one

We can now read a negative number. But the question that opened the chapter is still standing: given +6, what physical operation on its bits produces −6? There's a famous, almost suspiciously simple answer — invert every bit, then add one. I don't want to just hand it to you; I want you to watch it land on the right answer. Take +6 = 0110. Invert each bit (a job for the NOT gates from Chapter 2): 1001. Add one: 1010. Read it with our signed weights: −8+2 = −6. Exactly right. Step through it below — and try it in reverse, because negating −6 the same way marches you right back to +6.

4-bit signed value +6 1 −8·0 + 4·1 + 2·1 + 1·0 = +6 value invert · NOT add one
click a bit to change it — or hit Negate
Two moves, no subtraction: flip every bit, then add one. Run it twice and you're back where you started.
Fig 10. Negation with no subtraction. Take +6 = 0110; the leftmost column is worth −8, so its weight is what makes a number negative. Step once to invert every bit (NOT) → 1001 = −7, one short of the answer. Step again to add one and watch the carry ripple from the right → 1010 = −8 + 2 = −6. Hit Negate to run both moves at once, and again to come right back to +6 — the same two moves undo themselves. (Try 1000 = −8: it has no +8 twin, so it negates to itself.)

The source I learned this from said “you don't need to understand why — just invert and add one.” I refuse to leave it there, because the why is the most beautiful part, and it's not hard. This is arithmetic mod 2ⁿ — arithmetic on that circle we just drew, where counting past the top wraps to the bottom. Start with the step most books skip. Subtract x from all-ones, 1111, column by column. In every column you are computing either 1 − 0 or 1 − 1. Neither one ever borrows, because the top digit is already the largest a binary column can hold. So the columns never have to talk to each other. Each place independently gives 1 − 0 = 1, or 1 − 1 = 0. That is precisely “flip this bit.” Subtracting from all-ones doesn't merely match inverting; it is inverting: invert(x) = (2ⁿ−1) − x. Now add one: (2ⁿ−1) − x + 1 = 2ⁿx. And here's the magic step. On a wheel of 2ⁿ slots, 2ⁿ is a full lap; it lands you right back where you started, so 2ⁿ counts as 0. That means 2ⁿ − x is just −x. Invert-and-add-one isn't a trick; it's the shortest path around the circle to the negative. Trace the algebra live below.

the algebra · 4 bits, so 2ⁿ = 16 8 4 2 1 x = 6 flip: 15−x = 9 +1: 16−x = 10 16 − 6 = (one full lap) − 6 a full lap of 16 ≡ 0 → lands on −6 the wheel of 2ⁿ = 16 slots 6 x = 6 ◠ +16 = one full lap = back to 0 inside = raw value · outside = signed reading
step 1 — start with the number x = 6
Invert gives (2ⁿ−1)−x, add one gives 2ⁿ−x — and 2ⁿ is a full lap of the wheel, which is just 0. So you land on −x. Not a trick.
Fig 11. This is the whole reason invert-and-add-one works — no trick, just a lap of a wheel. Flipping every bit of x gives (2ⁿ−1) − x, because the all-ones number is 2ⁿ−1 and flipping is just subtracting from it. Add one and you have 2ⁿ − x. Now look at the wheel of 2ⁿ = 16 slots: counting up by a full 2ⁿ walks you all the way around and back to where you started — a full lap is 0. So 2ⁿ − x is just −x, and the answer drops onto the slot whose signed reading is exactly the negative. Invert-and-add-one isn't a recipe someone memorised — it's the shortest path around the ring to −x. Slide x and hit Trace it to watch the 2ⁿ collapse.

If “arithmetic that wraps around” still feels exotic, you already do it every single day — on a clock. Seven o'clock plus six hours isn't thirteen o'clock; it's 1. The hours live on a circle of twelve, and adding past the top wraps to the bottom. Now watch the move that actually matters. From seven o'clock, go back five hours and you land on two. From seven o'clock, go forward seven hours instead, which is twelve minus five, and you land on two again. The two walks are different lengths and they run opposite ways round the dial, and they still finish in the same slot. That's the rule: on a ring, subtracting x is identical to adding (N − x). That is precisely two's complement. Swap the clock's 12 for our 2ⁿ and the story is word-for-word the same. Spin the dial below and feel subtraction and addition become the same motion.

−x +(N−x) drag the blue hand around the dial · slot 0 at the top both hands land on 2 slot 2 · mod 12 75 = 2 7 + 7 = 2 14 wraps: 14 mod 12 = 2
go back 5 or forward 7 — same slot
locked — both land on 2
Going back x equals going forward N−x on a ring. Swap 12 for 2ⁿ and this is two's complement.
Fig 12. A clock already does this. It's 7 o'clock, wait 7 hours, and you land on 2 — not 14, because the dial only has 12 slots and the count wraps. Grab the blue hand and spin it, then set the step: the orange arc walks back x, the green arc walks forward N−x the other way round — and the two always meet on the same slot. Going back x is identical to going forward N−x. Swap the 12 for 2ⁿ and that single fact is two's complement: negating a number means replacing it with 2ⁿ − x, the distance the ring carries you the long way home.

04The range, and when it overflows

Because the width is fixed, the set of numbers we can name is fixed too. It's worth pinning down its exact edges, not hand-waving “about half positive, half negative.” For n bits the signed range runs from −2ⁿ⁻¹ to 2ⁿ⁻¹−1. In our four-bit world that's −8 to +7. Notice it's lopsided: one more negative than positive. That's not a bug, it's a head-count — and the head-count says which side gets the extra one. The top bit cuts the sixteen patterns cleanly in two: eight with it off, eight with it on. The eight with it on are all negatives, every one of them a genuine value, so they run −1 down to −8. The other eight have to pay for zero out of their own pocket. Zero is filed as non-negative, so it comes out of that half, leaving only seven positives. The negatives never had to fund it, so they keep all eight. The odd one out is 1000 = −8, the “lonely” value whose positive twin +8 won't fit in four bits at all. Walk the range line below and find the number with no mirror image.

Now aim the reflex you learned two sections ago at that lonely value. Negate 1000: invert it to 0111, add one, and you get 1000 straight back. The same pattern. Negation looked right at it and refused to move. That isn't the recipe failing. It's the recipe being exactly right. Negating means moving to the slot 16 − x, and 16 − 8 = 8. On a wheel of sixteen slots, slot 8 is the slot we call −8. They're the same notch, walked to from the two different sides. So −8 is its own negative, and it has to be: the +8 it should have travelled to fell off the end of the word. The lonely value has nobody to swap with.

the value +5 -8 4 2 1 its mirror — the −value −5 +8? off 16 patterns · 1 is zero · 15 left · 7 positive + 8 negative
0101 = +5 ↔ 1011 = −5. A matched ± pair.
One value on this line has no partner. Walk down past zero until the mirror falls off the end — who is the lonely one?
Fig 13. Fixed width, fixed range. Four bits give 16 patterns; two's complement spends them from −8 to +7. Walk the line and, for each value, watch its mirror — the same magnitude with the opposite sign — light up on the other side of zero. Every value pairs off… except one. Zero is its own reflection and costs a pattern, leaving an odd 15 to split — so the negatives get one extra. Land on −8 (1000) and its partner +8 falls right off the end: it would need a fifth bit that the width doesn't have. That is why the range is lopsided, and why −8 has no twin.

That hard edge matters the instant you do arithmetic, because addition can shove a result past the edge. When it does, the answer doesn't stop or error. It silently wraps around the wheel and comes back wearing the wrong sign. This is overflow. Add +5 and +4 in four bits: the true answer is +9, but +9 is off the top of the range, so the bits land on 1001 = −7. Two positives added to a negative — nonsense, and the machine said it with a straight face. Drive the adder below into overflow and watch a correct-looking sum turn poisonous.

the wheel · 16 codes, +7 meets −8 A +5 B +4 4-bit result · carry-out dropped reads as −7 true sum should be +9 OVERFLOW sign is a lie V=1
two positives summed to a negative — overflow
The adder never errors. It just wraps the wheel and hands back a wrong sign. Two positives that land negative — or two negatives that land positive — is the tell.
Fig 14. A 4-bit signed adder. Set A and B anywhere in −8…+7 and the hand sweeps from A around the wheel by B steps to the landing code. Stay inside the range and the sign holds. But +5 + +4 wants +9 — there is no +9 on a 4-bit wheel, so the hand sweeps clean past the +7 / −8 cliff and lands on 1001, which a signed reader calls −7. No error, no warning — just a wrong sign. The OVERFLOW flag (V) is the hardware catching exactly this: it lights whenever two same-sign operands produce an opposite-sign result. That single flag is the difference between a silent bug and a caught one.

The good news: overflow isn't mysterious, it's detectable, with a rule you can check at a single glance at three sign bits. Signed overflow happens exactly when you add two numbers of the same sign and the result comes out with the opposite sign. That's not a symptom somebody noticed. It's forced, and you can bound it yourself. Two positives are each at most +7, so their true sum is at most +14. That clears the +7 cliff, but it's nowhere near a full lap of 16. A sum that overshoots by less than one lap has exactly one place to land: the next stretch of wheel past the cliff, the negative half. It can't travel far enough to come back round into the positives, so the sign has no choice but to flip. Two negatives mirror it. Their true sum is at least −16, again less than a lap past the −8 cliff, so it can only spill up into the non-negative half wearing a fake positive sign. And a positive plus a negative can never overflow at all, because their true sum sits between them, safely inside the range. So the whole test is: operands agree in sign, result disagrees. Toggle the operand signs below and watch the overflow lamp light on exactly the like-signed rows that flip.

4-bit signed adder · holds only −8 … +7 + sign of A A +5 + + sign of B B +4 sign of result R −7 5 + 4 = 9 · past +7 → wraps to −7 the top (sign) bit flipped — that IS the overflow ! overflow B + B − A + A − + + same sign → can overflow + − opposite → safe − + opposite → safe − − same sign → can overflow
overflow — result sign flipped
Same-sign is the suspect; a flipped result sign is the proof. Opposite signs land inside −8…+7 every time, so they can never overflow.
Fig 15. Overflow isn't something you compute — it's something you spot. Every add here is 4-bit signed, so the answer must live in −8…+7. Set both operands positive and push their magnitudes up: 5 + 4 = 9 won't fit, so the top bit rolls over and the sum lands on −7 — a positive plus a positive came out negative. The overflow lamp lights. Flip one operand's sign and it goes dark and stays dark, no matter how you drag the sliders: a positive and a negative always land back inside the range. The whole test fits on the little map — overflow can only strike the two same-sign corners, and only when the result's sign disagrees with the operands you fed in.

One caution to plant now, because it's the single most common confusion in this whole area. The rule we just built — like-signed operands, result flips sign — is the signed-overflow rule, and it's about interpreting bits as two's complement. It is not the same thing as a bit carrying off the top end of the word, the carry-out, which is about unsigned wrap-around. Same eight bits, two completely different questions. “Did an unsigned sum exceed the width?” is the carry. “Did a signed sum leave the signed range?” is the overflow. In Chapter 14 the machine will keep a dedicated carry flag for the first question; the signed rule here is a separate story. Set the operands below and watch the same addition answer both questions independently — sometimes one fires, sometimes the other, sometimes neither.

sign bit A + B sum carry off top 8 4 2 1 THE UNSIGNED LENS 3 + 2 = 5 fits 0…15? CARRY-OUT · dormant THE SIGNED LENS +3 + +2 = +5 fits -8…+7? OVERFLOW · dormant
A = 0011 = unsigned 3 / signed +3 B = 0010 = unsigned 2 / signed +2
neither fires — the stored bits are correct in both lenses
Tip: click any A or B bit to flip it. The carry-out asks "did a bit fall off the top?"; overflow asks "did the carry into the sign bit and the carry off it disagree?" Two questions, one addition.
One 4-bit addition, read through two lenses at once. The unsigned lens asks a hardware question — did a bit fall off the top? That is the carry-out. The signed lens asks a two's-complement question — did the carry into the sign bit disagree with the carry off it? That is overflow. Try carry only (15 + 1) and overflow only (7 + 1): the same adder, the same bits, and the two flags fire on completely different rows. Sometimes one, sometimes the other, sometimes both, sometimes neither — a distinction we will lean on hard in Chapter 14.

05One adder, subtraction for free

Now the payoff this whole chapter was built toward — and it's the reason two's complement won, out of all the schemes people tried. We never have to build a subtractor. Subtraction is defined away. A − B is just A + (−B), and we already know how to make −B: invert its bits and add one. So to compute 7 − 5, the machine negates 5 into −5 and feeds 7 and −5 into the very same adder it uses for two positives. The adder does its dumb column-by-column job. The top carry falls off the end and vanishes (a full lap around the wheel, worth zero), and out comes 2. It never knew it was subtracting. Watch a subtraction become an addition, step by step, below.

the subtraction how −B is made the one adder — identical circuitry for + and − 4-bit adder · dumb column-by-column 1 2 4 −8 + A −B
A−B is A+(−B). Watch the negate-then-add flow through the one adder — it never learns it subtracted.
Fig 17. The payoff of the whole chapter: a machine with no subtractor in it subtracting anyway. Pick any A − B and step it through. The subtraction rewrites itself as A + (−B); −B is built by the two-step reflex — flip the bits, add one; then A and −B pour into the identical four-bit adder, column by column, carries and all. On 7 − 5 the top carry drops off the end — a full lap around the wheel, worth 0 — and out falls 2. The adder did the same dumb column-add it always does. It never knew it subtracted, and that's exactly why two's complement won.

A claim this clean deserves to be checked exhaustively, not just on the examples I happened to pick. That's the honest thing to do, and in a four-bit world it's cheap: there are only 16 × 16 = 256 possible sums, so we can test every single one. The figure below runs a short program, live in this page, that adds all 256 pairs as two's-complement four-bit values, compares each against the true mathematical answer, and flags exactly the ones that overflow. Then it confirms that the overflow flag it raises matches our like-signed rule on all 256, with zero disagreements. The representation isn't “usually” right; it's provably right across the entire space.

b (second addend) → a (first addend) →
pairs tested0/256
overflows flagged0
rule = truth0/256
disagreements0
Press run — the program adds all 256 pairs as 4-bit two's complement.
Figure 18 — Proof by exhaustion. There are only sixteen 4-bit numbers, so only 16×16 = 256 possible sums exist — few enough to test all of them. The program adds every pair as two’s complement, wraps it to 4 bits, and compares to the true answer: green cells fit the −8…7 range, gold cells overflow. Then it checks the shortcut rule — overflow happens only when two like-signed numbers produce a result of the opposite sign — against the truth on all 256. Run it: the rule agrees on every pair, with zero disagreements. That’s not a spot-check. That’s a proof.

And that's Chapter 5 — you can now write negative numbers with nothing but 0s and 1s. The move was one reinterpretation: make the top column's weight negative, and the plain place-value machine from Chapter 4 quietly starts naming negatives too. That bent the number line into a circle, put −1 at all-ones and −8 at the top bit, and made negation a two-step reflex — invert and add one. That reflex is nothing more exotic than arithmetic mod 2ⁿ, the same wrap-around a clock lives by. You pinned the range to −8…+7, learned to catch overflow with the like-signed rule, and kept it firmly distinct from the unsigned carry still to come. And then the prize dropped out for free: one adder, fed a negated operand, is a subtractor. That's the perfect place to stand, because next chapter we finally build that adder for real — out of the XOR and AND gates from Chapter 2. And we'll discover, with a small jolt, that those two gates were addition in disguise the whole time.

iolinked.com
Written by Ajai Raj