S14 · Computer Studies II · Grade 11 · ages 16–17
Binary Arithmetic
Signed numbers, addition and subtraction
Grade 11 · 1.2 Binary Arithmetic OperationsCBE strandFree · works offline
▶ Start the interactive lessonThe full lesson adds narration, an interactive mission and a 10-question bank, and the quiz explains any mistakes.
Adding in binary
Binary addition has four rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1), and 1 + 1 + 1 = 11 (write 1, carry 1). Add column by column from the right, just like decimal: 0101 + 0011 = 1000, which is 5 + 3 = 8.
Unsigned numbers
An unsigned number has no sign, so it can only be zero or positive. With 8 bits, unsigned values run from 0 (0000 0000) to 255 (1111 1111). If a result needs more bits than you have, it overflows and the answer is wrong.
Sign and magnitude
To store negative numbers, one simple method uses the leftmost bit as a sign: 0 for positive, 1 for negative. In 8 bits, +5 is 0000 0101 and −5 is 1000 0101. The problem: it has two zeros (+0 and −0), and adding signed numbers this way does not work directly.
One's and two's complement
One's complement makes a number negative by flipping every bit: +5 = 0000 0101 becomes 1111 1010. Two's complement flips every bit and then adds 1: −5 = 1111 1011. Two's complement has only one zero, and computers use it because ordinary addition then works for negative numbers too. With 8 bits it covers −128 to +127.
Subtracting by adding
Computers subtract by adding the two's complement. To work out 7 − 5: write +7 as 0000 0111 and −5 as 1111 1011, then add them, giving 1 0000 0010. Drop the extra carry on the left and the answer is 0000 0010, which is 2. One adding circuit can do both jobs.
Key points
- In binary, one plus one is one-zero: write zero and carry one.
- Unsigned eight-bit numbers go from zero to two hundred and fifty-five.
- Sign and magnitude uses the first bit as the sign, but it has two zeros.
- One's complement flips every bit.
- Two's complement flips every bit, then adds one.
- Eight-bit two's complement covers minus one hundred and twenty-eight to plus one hundred and twenty-seven.
- Computers subtract by adding the two's complement.
Try it for real: Work it out by hand
- Add 0110 + 0111 in binary and check your answer in decimal.
- Write −12 in 8-bit sign and magnitude, one's complement and two's complement.