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.
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.
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.
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.
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.
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.
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.
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.
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.
= −128
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.