The Negative Number Machine
How do you store a minus sign in bits?
Your mission
Computers only have 0s and 1s, so they need clever tricks to store negative numbers. Feed numbers into the machine and watch it turn them into signed magnitude, one's complement and two's complement. Then hunt down the mystery of the two zeros.
Explore
Send −22 through the machine, one stage at a time, and see what each system does to the bits.
Computers have no minus sign, only bits. So how do they store −22? This machine shows three ways. Press Next stage to send −22 through it, one stage at a time, using 8 bits.
0 of 3 systems seen
Experiment
Run the machine with at least two different numbers, and investigate the two zeros.
0 of 2 numbers, zeros not investigated yet
Challenge
Build the bit patterns yourself, and work out what mystery patterns mean, in six tasks.
Complete all 6 tasks to continue.
Understand
Here is what the machine was doing, in the words you need for the exam.
Three ways to store −22 in 8 bits
Start from +22 = 00010110.
| System | Rule | −22 | Zeros | 8-bit range |
|---|---|---|---|---|
| Signed magnitude | Leftmost bit is the sign (0 = +, 1 = −). The other bits are the size. | 10010110 | Two: +0 and −0 | −127 to +127 |
| One's complement | Invert every bit of the positive number. | 11101001 | Two: +0 and −0 | −127 to +127 |
| Two's complement | Invert every bit, then add 1 (within the bit width). | 11101010 | Just one | −128 to +127 |
Why computers choose two's complement
- There is only one zero. Making −0 gives 1 00000000, and the extra carry falls off the end, leaving 00000000.
- The pattern that would have been −0 is used for one more number, −128.
- Ordinary binary addition just works, even with negative numbers.
Reading a two's complement number
If the leftmost bit is 0, the number is positive: read it normally. If it is 1, the number is negative: invert and add 1 to find its size.
11101010 → invert: 00010101 → add 1: 00010110 = 22, so the value is −22.
Same bits, different meanings
A bit pattern means nothing until you know which system it uses. 10010110 is −22 in signed magnitude, but −106 in two's complement. That's why exam questions always say which system to use.
Exam tip
Always write down the positive number first, using the full number of bits (for example, +22 = 00010110), then apply the rule. And when you add 1 for two's complement, carry just like normal addition, but stay within the bit width.