Skip to content

Demo 1.3: Arithmetic Without a Minus Sign

The previous two demonstrations were about writing quantities down. This one is about doing something with them, and it runs into a problem almost immediately.

A circuit has two voltages. It has no third symbol to spend on a minus sign, no separate place to record that a value is negative, and no way to mark a number as special. Whatever “negative” is going to mean, it has to be built out of the same bits that are already carrying the number, and it has to be built in a way that a row of identical gates can act on without knowing what it is doing.

That constraint is much tighter than it looks, and it is the reason this topic has an answer that nobody guesses first time.

Binary addition itself is not difficult. Work from the right, add what is in each column, write down what fits and carry what does not. There are four cases and three of them are dull: 0 + 0 is 0, 0 + 1 is 1, 1 + 0 is 1. The fourth is 1 + 1, which is 2, and 2 will not fit in one bit. In binary it is 10, so you write 0 and carry 1.

Everything awkward about adders comes from that one line, and the first tab is really an excuse to watch a carry appear and travel along a row of columns.

The harder problem starts on the second tab. Spending the top bit on a sign is the idea everyone has, it is perfectly readable, and it very nearly does not work at all. Seeing precisely how badly it fails is what makes the answer on the third tab feel inevitable rather than arbitrary.

Adding bits starts at one bit wide and goes up to four, with the answer allowed a fifth bit when it needs one. Set the two numbers with the bit toggles or use the presets, then press Do it column by column and step through the sum one column at a time. The rule in use lights up in the panel underneath as you go. Start at one bit and press 1 + 1, because the whole difficulty of the subject is visible there.

A bit for the sign takes the obvious approach to negative numbers and tests it honestly. Choose two values, watch them added as ordinary binary, and read the verdict. There is a table of all sixteen patterns showing the two different zeros, and a panel that has tried every pair in range and counted how many come out right.

Two’s complement keeps the sign bit and gives it a negative weight. The weight strip at the top can be clicked, and every pattern of bits is a legal number. There is a stepper that shows the invert-and-add-one procedure a line at a time, the full sixteen-pattern table again, and an addition panel whose operands are deliberately fenced in so that nothing here overflows.

Subtraction is addition does ab by negating b and adding. Step through it to see the negation happen before the sum. There are presets at four and six bits, including both of the worked examples from the reading.

Binary Arithmetic and Negative Numbers

Adding with carries, two attempts at writing a negative number, and why no computer has a subtractor.

Binary addition is the addition you already know, with fewer symbols.

  • Start at the right-hand column and work leftwards.
  • Add what is in the column, write down the answer, carry anything that will not fit.
  • There are only four cases, and three of them are dull.
  • The fourth is 1 + 1, which is 2, and 2 does not fit in one bit.
  • In binary 2 is written 10, so you write 0 and carry 1.
  • Every complication below comes from that one line.
How wide
Try
A = 1
B = 1
The sum on paper
c10
A1
+ B1
=10

1 + 1 = 2

  • Every column is done, and the carry out of the leftmost column is 1.
  • So the answer needs 2 bits rather than 1.
  • The 1 bits of the sum read 0, which is short by 2, and the missing amount is sitting in that extra bit.
The whole rule
0 + 0 = 0write 0, carry 0
0 + 1 = 1write 1, carry 0
1 + 1 = 10write 0, carry 1
1 + 1 + 1 = 11write 1, carry 1
  • A column holds at most three bits: its own two, plus one carried in.
  • So its total can only ever be 0, 1, 2 or 3.
  • Two is written 10 and three is written 11.
  • Write down the bottom bit of the total and carry the top bit.
  • Step through a sum and the rule in use lights up.
Why the fifth bit
  • Four bits hold 0 to 15, so the largest sum is 15 + 15, which is 30.
  • That does not fit in four bits, so a four-bit adder must produce a five-bit answer.
  • The extra bit is the carry out of the leftmost column.
  • It is not a special case: it is an ordinary carry arriving in a column that does not exist yet.
  • Set the width to 1 and press 1 + 1 for the same idea in miniature.
  • One bit plus one bit needs two bits of answer, so even the smallest adder has this problem. Everything wider is that, repeated.
Carries are the only difficulty
  • Press No carries and step through it. Every column is independent and the answer appears as fast as you can read it.
  • Now press Ripple all the way, which is 7 + 1, and step through that.
  • Each column has to wait for the one to its right before it can say anything.
  • That waiting is invisible on paper.
  • It is the single most important fact about adder circuits, which is why the demonstration on adders comes back to it.
No minus sign anywhere
  • Everything on this tab is positive, and that is not an oversight.
  • A circuit has two voltages and no third symbol to spend on a sign.
  • So a negative number is not free. It has to be built out of the bits you already have.
  • The next tab tries the obvious way of doing that. The tab after it shows the way that works.

Step 1: Start with the smallest possible adder

Section titled “Step 1: Start with the smallest possible adder”

Open Adding bits, set the width to 1 bit and press 1 + 1.

One bit plus one bit gives an answer that does not fit in one bit. That is the entire problem, stated in the smallest possible form, and it does not go away at any width: it is why an adder has two outputs rather than one, and why the demonstration on adders later has a Sum pin and a Carry pin instead of just an answer.

Now go to 4 bits and press The largest it goes. Fifteen plus fifteen is thirty, which needs five bits, and the panel says so. The extra bit is not a special case bolted on the end. It is an ordinary carry, arriving in a column that does not exist.

Still at four bits, press No carries, which is 5 + 10, then press Do it column by column and step through it.

Every column is independent. Each one has both its bits from the start and none of them is waiting for anything.

Now press Ripple all the way, which is 7 + 1, and step through that. Read the commentary as each column completes: the rightmost produces a carry, which the next column needs before it can say anything, which produces another carry, and so on all the way to the left.

On paper this costs you nothing but patience. In a circuit it costs time, and the demonstration on adders is largely about how much. It is worth noticing here, while the arithmetic is simple enough that the waiting is the only thing to look at.

Step 3: Try the obvious way to write a negative number

Section titled “Step 3: Try the obvious way to write a negative number”

Open A bit for the sign. The scheme is exactly what it sounds like: the top bit says which way, the other three say how much, so 0101 is +5 and 1101 is −5.

Press 5 + -5, which should give zero.

It gives +2. Look at the columns and you can see why, and it is worth being precise about the reason, because the adder has done nothing wrong. It added the sign column exactly as it added every other column, carried into it and out of it as usual, and produced a perfectly correct four-bit sum. The bits were fine. The meaning attached to the top bit was not something the arithmetic could know about.

Now press 2 + 3 and watch it work. That is not a reprieve, it is the diagnosis: both numbers are positive, so both sign bits are 0, nothing is carried into the sign column, and the magnitudes simply add.

The table of all sixteen patterns has 0000 and 1000 highlighted, and they are +0 and −0. There is no such number as negative zero, so one of the sixteen patterns has been wasted. The waste is the smaller problem. The larger one is that a circuit asked whether two values are equal now has to know that these two patterns are equal despite differing in a bit, so even a test for zero stops being a matter of looking at the bits.

Then read the counting panel, which is the honest verdict. Every pair whose answer is representable was tried, and 58 out of 169 come out right. That sounds survivable until you look at what the 58 are:

  • 36 have both numbers non-negative, so the sign bit is never used
  • 14 add zero to something, so nothing is really being added
  • 8 work by coincidence, and every one of them involves −4

The coincidences are the best part. A magnitude of 4 is exactly half of 8, so adding it pushes a carry out of the three-bit magnitude field and into the sign column, where it flips the sign to the very value that was wanted. Nothing reasoned about signs. A carry escaped from one field into another and happened to land correctly.

So the scheme works when you are not using the feature it exists to provide, when you are adding nothing, or by accident.

Open Two’s complement and look at the strip at the top.

The columns are worth −8, 4, 2 and 1. That is the only change. Every other column is exactly what it was in the first demonstration of the module, and a number is still the sum of the weights standing under its 1s. The top bit is no longer a label announcing that a number is negative, it is an ordinary column that happens to count downwards, and because it is an ordinary column, ordinary addition works on it.

Click the bits and watch the value. Then check the pattern table: sixteen patterns, sixteen different numbers, one zero. Read the right-hand column upwards from 1111 and it counts −1, −2, −3, which is worth noticing, because the negative numbers are not stored backwards or in any special order. They simply carry on counting down past zero and wrap round to the top of the field.

Now use the addition panel. Try a few pairs, including ones with a negative in them, and note that the verdict is always correct. Nothing on this tab knows anything about signs. The columns were added from the right, carries went where carries go, and the answer came out right.

That is the whole claim for two’s complement, and it is a claim about hardware rather than about notation: the four-bit adder built out of gates later in this module adds signed numbers correctly without a single gate being added to it, because there is nothing to add.

Still on the same tab, set the negation stepper to 5 and press Step through it. Invert every bit to get 1010, add one to get 1011, and that is −5.

Now set it to −8.

Inverting and adding one gives −8 back again. That is not a fault in the procedure, it is the procedure telling the truth: +8 needs one more bit than a four-bit field has, so there is no pattern for it. There are sixteen patterns, one of them is zero, and the remaining fifteen cannot be split evenly between positives and negatives. The odd one out is the most negative value, which is why the range runs from −8 to +7 rather than symmetrically.

This is not a curiosity. Taking the absolute value of the most negative integer is a well-known source of bugs in real software, and it has never been fixed because there is nothing to fix.

Open Subtraction is addition and press 7 − 5, then Step through it.

Watch the three stages. Five is 0101, inverting gives 1010, adding one gives 1011, which is −5. Then add 0111 and 1011 in the ordinary way and the answer bits read 0010, which is +2.

A carry came out of the top column and was discarded, and that always looks like cheating the first time. It is not. A field of n bits counts in a circle of 2ⁿ values, adding walks you round that circle, and the carry out is simply the moment you pass the starting point. It records that a lap was completed and nothing else.

Notice too that the carry is not an error signal. Press 2 − 6, which gives −4 correctly and produces no carry out at all. Whether a carry appears depends on which two numbers you picked, not on whether the answer is right.

Then switch to six bits and press −25 + 18, which is the larger example from the reading. It gives 111001, which is −7.

The point of all this is a saving in hardware rather than in effort. An adder that can also subtract needs one inverter per bit and one spare input: feed a control line into every inverter and into the carry in at the bottom of the chain, and with it at 0 you get A + B, while with it at 1 every bit of B is inverted and a 1 arrives at the bottom, which is inverting and adding one. One wire turns an adder into a subtractor. That is a remarkable return on a change of notation, and it is why two’s complement is not merely a tidy idea but the one that everybody uses.

Quiz
Select 0/1

Why does a one-bit adder need two output bits?

Quiz
Select 0/1

Under sign and magnitude, adding +5 and −5 as ordinary binary gives 0010, which reads as +2. What has gone wrong?

Concept Match

Match each idea to what it actually does

Quiz
Select 0/1

A four-bit two's complement subtraction produces a carry out of the top column, which is discarded. What does that carry tell you?

Quiz
Select 0/1

Why can −8 not be negated in a four-bit two's complement field?

Five things to carry forward.

  1. Binary addition is one rule. A column totals 0, 1, 2 or 3; write its bottom bit and carry its top bit. Everything else is bookkeeping.
  2. Two bits will not add into one bit, so an adder always produces one more bit than it consumes. This is true at one bit wide and at sixty-four.
  3. A sign bit that is only a label breaks arithmetic. It fails on 111 of 169 pairs, and most of the successes are cases where it was not being used.
  4. A sign bit with a negative weight fixes it completely, and costs nothing in hardware. The same row of adder cells works on signed and unsigned numbers without modification, because there is nothing to modify.
  5. Subtraction is addition. Negate the second operand and add, which needs one inverter per bit and one control wire, and no subtractor anywhere.

Everything here has been kept carefully inside the range. The operands on the last two tabs are fenced in, and that fence is hiding something real: a fixed-width field holds only so many values, and asking it for one it does not have produces an answer that is not merely approximate but wrong, and wrong without any complaint from the hardware.

That is overflow, and it needs its own demonstration. It comes next, along with the vocabulary for how big these fields are in the first place: the bit, the nibble, the byte and the word.