1011 Two's Complement Workbench
Bits
Read as

A bench for signed binary

One pattern, five meanings.

The hardware only stores bits. Whether a pattern means 11, −3, −4, −5 or +3 depends on the encoding everyone agrees to use. Pick an encoding in the bar above and every instrument on this page switches with it. Click the bits on the right to change the pattern.

Instrument 1

The wheel

A fixed number of wires can only count in a circle: one step after the last pattern, the carry falls off and you're back at all zeros. Every encoding uses this same circle and only changes the labels. The coloured ring inside shows whether each clockwise step really adds exactly 1.

positive negative zero (dashed = duplicate zero) step adds 1 step breaks counting step adds 0

Two rules a blind adder needs

Turn the wheel

Click any slot to move the hand. Adding a number means turning the wheel forward by that number's pattern, read as a plain count.

Press Turn to add the number above, or try the presets. Watch the hand go almost all the way round to subtract.

Instrument 2

The full map

Every pattern at the current width, read all five ways. The positive half is identical everywhere; the encodings only disagree once the top bit turns on. Hover a row to find it on the wheel; click to move the hand there.

Instrument 3

The blind adder

The adder circuit has no idea what the bits mean. It adds columns right to left, passes carries along, and drops whatever falls off the left end. Then we read the result with each encoding and see which ones got the right answer for free, and which need extra hardware to patch it up.

A
B

Status flags the CPU sets

Same adder, five readings

Instrument 4

Every possible sum

Each cell is one addition A + B, pushed through the adder. Green means the bits came out right, red means the encoding broke it, amber means the true answer doesn't fit in this many bits at all (real overflow, which no encoding can avoid). Click a cell to load it into the adder.

Rows are A, columns are B, both sorted from lowest to highest value.

All five, adder only

Percent of the sums that fit which come out right with no fix-up hardware. Click one to switch.

Instrument 5

What the top bit is worth

In sign-magnitude the top bit is a detached flag. In two's complement it is an ordinary column with a negative weight, so the value is just a sum. Toggle bits and watch the arithmetic.

Flip and add 1, explained

Uses the pattern on the left, read as two's complement.

Instrument 6

Making a number wider

Moving a value into more bits (an 8-bit value into a 16-bit register) has to keep its meaning. Copper bits are the new ones. In two's complement you copy the top bit leftwards and you're done.

Instrument 7

Scorecard

Everything the instruments above showed, in one table. Green is a hardware win, red is extra cost or a trap. Two's complement isn't perfect (it has the asymmetric range and the lonely most-negative value), but it wins every row that matters for an integer ALU.