Number Systems: Question 3
Syllabus 1.1
A weather station stores each sensor reading as an 8-bit unsigned binary number in its onboard memory, and its processor sometimes needs to add two readings together.
(a) Add the two 8-bit binary numbers 01011011 and 00100101 using binary addition. Show your working, and give your answer in binary. [3]
(b) Add the two 8-bit binary numbers 10110110 and 01101011 using binary addition. Show your working, and give your answer in binary. [3]
(c) State whether an overflow error occurs for the addition in part (b), and explain your answer. [2]
Show worked solution Hide worked solution
Worked solution
Part (a): Adding 01011011 and 00100101
Add the two 8-bit numbers column by column from bit 0 (rightmost) to bit 7 (leftmost), carrying a 1 into the next column whenever a column totals 2 or more.
01011011
+ 00100101
- bit 0: 1 + 1 = 0, carry 1
- bit 1: 1 + 0 + carry 1 = 0, carry 1
- bit 2: 0 + 1 + carry 1 = 0, carry 1
- bit 3: 1 + 0 + carry 1 = 0, carry 1
- bit 4: 1 + 0 + carry 1 = 0, carry 1
- bit 5: 0 + 1 + carry 1 = 0, carry 1
- bit 6: 1 + 0 + carry 1 = 0, carry 1
- bit 7: 0 + 0 + carry 1 = 1, carry 0 (nothing carried out of the register)
Result: 10000000
Check using denary: 01011011 = 91, 00100101 = 37, and 91 + 37 = 128, which equals 10000000. Correct, and no carry was produced out of bit 7.
Part (b): Adding 10110110 and 01101011
10110110
+ 01101011
- bit 0: 0 + 1 = 1, carry 0
- bit 1: 1 + 1 = 0, carry 1
- bit 2: 1 + 0 + carry 1 = 0, carry 1
- bit 3: 0 + 1 + carry 1 = 0, carry 1
- bit 4: 1 + 0 + carry 1 = 0, carry 1
- bit 5: 1 + 1 + carry 1 = 1, carry 1
- bit 6: 0 + 1 + carry 1 = 0, carry 1
- bit 7: 1 + 0 + carry 1 = 0, carry 1 (a 1 is carried out beyond the register)
Result stored in the 8-bit register: 00100001, with an extra 1 carried out beyond bit 7.
Check using denary: 10110110 = 182, 01101011 = 107, and 182 + 107 = 289. Since 289 needs 9 bits to represent exactly, only the lowest 8 bits fit in the register: 289 - 256 = 33, which equals 00100001. The extra 1 (worth 256) is lost.
Part (c): Overflow in part (b)
An overflow error does occur in part (b). The true sum, 289, is larger than the largest value an 8-bit register can hold (255), so a 1 had to be carried out beyond the bit 7 column during the addition. Since the register can only store 8 bits, that carried-out bit is lost, leaving the register holding 00100001 (33) instead of the correct value, 289. (By contrast, part (a)‘s addition produced a final carry of 0 out of bit 7, so no overflow occurs there.)
Final answers
- (a)
01011011+00100101=10000000(no overflow) - (b)
10110110+01101011=00100001, with a 1 carried out of the register - (c) Yes, an overflow error occurs, because the correct sum (289) needs 9 bits and cannot fit in the 8-bit register.