AQA 7517, section 4.5.4.2
You need to be able to add and multiply two unsigned binary integers. The methods are the same as in decimal, but with only two digits.
Binary addition
The rules for adding single bits are:
| Sum | Result |
|---|---|
| 0 | |
| 1 | |
| 10 (write 0, carry 1) | |
| 11 (write 1, carry 1) |
Work from the right, adding each column and carrying to the next.
Add (6 + 7):
Right to left:
- .
- : write 0, carry 1.
- : write 1, carry 1.
- .
The answer is . ✓
Add (11 + 6):
The answer is . Notice that the result needs 5 bits, although both numbers fit in 4.
Overflow
If the result needs more bits than are available, the extra carry is lost and the stored answer is wrong. This is an overflow error.
In 8 bits, (192 + 64) should give 256, which needs nine bits. The ninth bit is dropped, so the stored result is .
Binary multiplication
Multiplication uses shift and add, the same as long multiplication in decimal. For each bit of the multiplier, working from the right:
- if the bit is 1, write the multiplicand (shifted left by the bit's position);
- if the bit is 0, write zeros (or nothing).
Then add all of the partial products.
Multiply (5 × 3):
The answer is . ✓
Multiply (13 × 5):
. ✓ (.)
Multiplying by 2
Shifting a binary number left by one place doubles it, because each place value is twice as big. So (). This is the reason that shift-and-add works.
Worked example
Task: add in 8 bits, and say whether overflow occurs.
Working right to left, the carries ripple all the way along, and there's a carry out of the leftmost bit. The result is , which is 9 bits. In 8 bits only is stored.
The correct answer is , and . Overflow has occurred, because 288 is more than the 8-bit maximum of 255.
Exam tip: show the carries and line up the columns. For multiplication, show each partial product, with its shift, before adding them. Check the answer by converting to decimal.
Check yourself
Add
(5 + 3 = 8).
What is ?
(3 × 3 = 9). Partial products are and , which add to .
What causes an overflow error in binary addition?
The result is too large to fit in the number of bits available, so the carry out of the leftmost bit is lost.
What happens to a binary number when it is shifted left one place?
It is multiplied by 2.