Binary addition and overflow

GCSE Computer Science (Edexcel) · Edexcel 1CP2 · 2.1.4, 2.1.5 · Data › Binary

66 exam-style questions plus unlimited generated ones on this topic, at up to four difficulty levels, with full mark schemes. Notes and past-paper booklets are open to everyone. Practice needs a free account.

Or take a quick quiz: 10 questions on this subtopic in GCSE Computer Science (Edexcel), marked as you tap.

Revision notes

How to add two positive 8-bit binary numbers using the binary addition rules, and what an overflow is and why it happens. Expect a 2-mark addition and 1 to 4 marks explaining overflow, often in a context such as a counter.

Key facts

  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 1 = 0 carry 1
  • 1 + 1 + 1 = 1 carry 1
  • Overflow: a result too large for the number of bits available
  • 8-bit unsigned overflow: a total above 255, shown by a carry out of the MSB
  • After an 8-bit overflow, the stored result = true total − 256
  • Grade 9+ only Two's complement overflow: two positive numbers give a result with an MSB of 1 (it looks negative)

Notes

The rules for adding binary

  • 0 + 0 = 0, and 0 + 1 = 1.
  • 1 + 1 = 2, which is 10 in binary: write 0 and carry 1 into the next column.
  • 1 + 1 + 1 (including a carried 1) = 3, which is 11 in binary: write 1 and carry 1.

Adding two 8-bit numbers

diagram
  • Write one number above the other, with the columns lined up. Start at the right (the least significant bit) and work left.
  • Write each carry clearly under the next column so that you remember to add it.
  • Example (the denary values are in brackets):
      0110 1011  (107)
    + 0011 0110   (54)
    = 1010 0001  (161)
  • 0110101100110110+11111110100001carries(107)(54)(161)
    Work from the right. Each carry (red) is added into the next column to the left
  • Check by converting to denary: 107 + 54 = 161, and 1010 0001 = 128 + 32 + 1 = 161.

Overflow

diagram
  • An overflow happens when the result of a calculation is too large to be stored in the number of bits available.
  • 8 bits can store up to 255. If two 8-bit numbers add up to more than 255, a 1 is carried out of the most significant bit: the result needs a 9th bit that does not fit.
  • The extra bit is lost, so the stored result is wrong. Example: 1100 1000 (200) + 0110 0100 (100) = 1 0010 1100 (300), but only 0010 1100 (44) is stored.
  • 1100100001100100+100101100carries(200)(100)(44)19th bit lostonly 8 bits are stored
    Overflow: 200 + 100 = 300 needs 9 bits. The carry out of the MSB is lost, so 44 is stored
  • Consequences: a wrong value is stored and used in later calculations or decisions, or the program reports an error or crashes.
  • To avoid it, use more bits for the value, or make the program check for overflow.
  • Two's complement: two positive numbers can add up to more than +127 without a carry out. The carry into the MSB makes the result look negative, e.g. 0110 0000 (96) + 0101 0000 (80) = 1011 0000, which reads as −80. This is still an overflow. Grade 9+ only

How to answer each type of question

Add two 8-bit binary numbers

2 marksGrade 5
  1. Line up the columns and start at the right.
  2. Use the rules: 1 + 1 = 0 carry 1, and 1 + 1 + 1 = 1 carry 1.
  3. Write every carry under the next column.
  4. Check by converting both numbers and your answer to denary.

Example. Add these two 8-bit binary numbers. Give your answer as an 8-bit binary number.

  0101 1101
+ 0010 0111

Show the model answerHide the model answer
0101110100100111+111111110000100carries
1000 0100
Left-hand four bits 1000 (1); right-hand four bits 0100
(1)
(Check: 93 + 39 = 132 = 128 + 4.)

Explain why an overflow has occurred

2 marksGrade 6
  1. Work out the true total (in denary if that helps).
  2. Compare it with 255, the largest value 8 bits can store.
  3. Say that the carry out of the MSB is lost, and give the wrong value that is stored if you can.

Example. A car park counter stores the number of cars as an 8-bit unsigned binary integer. It currently holds 1111 0000. Another 0001 0100 cars arrive.
Explain why the counter will not show the correct total.

Show the model answerHide the model answer
240 + 20 = 260, which is larger than 255, the largest value 8 bits can store (1). The result needs 9 bits, so an overflow occurs: the carry out of the most significant bit is lost and only 0000 0100 (4) is stored (1).

Describe how binary addition works and how overflow is detected

3 to 4 marksGrade 7
  1. Say that the bits are added column by column from the right.
  2. Give the carry rules.
  3. Say that a carry out of the leftmost column means the result does not fit: an overflow.

Example. Describe how a processor adds two 8-bit unsigned binary numbers and how it can tell that an overflow has occurred.

Show the model answerHide the model answer
The bits are added column by column, starting with the least significant (rightmost) bit (1). 1 + 1 gives 0 with a carry of 1 into the next column (1). A carried 1 is added into the next column, so 1 + 1 + 1 gives 1 carry 1 (1). If a 1 is carried out of the most significant (leftmost) bit, the result needs 9 bits, so an overflow has occurred (1).

Explain an overflow in two's complement addition

2 marksGrade 9
  1. Work out the correct total and compare it with +127.
  2. Say that the carry into the sign bit makes the MSB 1.
  3. Say that two positive numbers have given a negative-looking result, which shows an overflow.

Example. Two 8-bit two's complement integers, 0100 1100 (+76) and 0011 1000 (+56), are added. The result is 1000 0100.
Explain why this result is wrong.

Show the model answerHide the model answer
The correct total is +132, which is larger than +127, the largest value 8-bit two's complement can store (1). The carry into the sign bit makes the MSB 1, so the result reads as −124: adding two positive numbers has given a negative result, so an overflow has occurred (1).

Don’t lose marks

  • Writing 2 in a column. Binary only has 0 and 1: 1 + 1 is 0 carry 1.
  • Forgetting to add the carried 1 into the next column.
  • Starting the addition from the left instead of the right.
  • Defining overflow as 'the number is too big' without adding 'for the number of bits available'.
  • When asked for the 8-bit result after an overflow, writing all 9 bits. Leave off the carried-out bit, and say that an overflow has occurred.

More tips

Memory tricks

  • Say it as you add: 'one plus one is nought, carry one'; 'one plus one plus one is one, carry one'.
  • Estimate in denary first. If the two values add up to more than 255, expect an overflow.
  • Quick overflow test for 8-bit unsigned numbers: if both numbers have a 1 in the MSB, there will always be an overflow (128 + 128 = 256).
  • Look at the last column: a carry left over after the leftmost bit means an overflow.

Exam technique

  • Show your carries. Clear carries make it easier to find a slip when you check your answer.
  • In overflow explanations, give the numbers: the true total, the limit of 255 and the fact that the 9th bit is lost.
  • Use the context: say what goes wrong in the scenario (e.g. the counter shows 4 cars instead of 260).
  • Addition answers are often marked in groups of four bits, so write your answer as two nibbles.

What each grade needs

What you need to be able to do, from the first marks up to the top grade.

  1. Grade 4
    Use the four binary addition rules0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 0 carry 1, and 1 + 1 + 1 = 1 carry 1.
  2. Grade 5
    Add two 8-bit binary numbersAdd column by column from the right, carrying 1 into the next column when needed.
  3. Grade 5
    Define overflowAn overflow happens when a result is too large to be stored in the number of bits available.
  4. Grade 6
    Spot an overflow in an 8-bit additionA 1 carried out of the most significant bit means the result needs 9 bits.
  5. Grade 7
    Explain the effect of an overflowThe carried-out bit is lost, so the stored result is wrong (256 less than the true total for 8 bits).
  6. Grade 9
    Explain overflow when adding two's complement numbersTwo positive numbers with a total above +127 give a pattern with an MSB of 1, which reads as negative.

Quick recall

Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.

Define the term 'overflow error'.
The result of a calculation is too big to fit in the number of bits available.
State the largest score that the scoreboard can store for one team.
255
How many different values can be stored in one 8-bit unsigned binary integer?
256
Words: carry, overflow, parity, checksum
When 1 + 1 is added in one column, 0 is written and a ____ is added to the next column on the left. If a carry comes out of the left-hand column of an 8-bit addition, an ____ error occurs.
Write one word from the box in each gap.
carry; overflow
In binary addition, the 1 that is moved on to the next column on the left is given a name. State the name.
carry
In an 8-bit addition, an overflow error shows itself as a carry out of the left-hand column. State the place value of this left-hand column.
128

Sample questions

Written for this site in the style of Edexcel exam questions. They are not taken from real past papers.

Question 1Easy4 marks
Two 8-bit unsigned binary numbers are added: 0001 0011 and 0000 1101.
(a) Calculate the sum of the two binary numbers. Give your answer as an 8-bit binary number.
[2]
(b) State whether an overflow has occurred. Give a reason for your answer.
[2]
Show the answer and mark scheme
(a) Answer: 0010 0000
  • binary addition with carries, with at least 7 of the 8 bits correct
  • 0010 0000
(b) Answer: No: there is no carry out of the MSB (32 ≤ 255).
  • no (overflow has not occurred)
  • there is no carry out of the most significant bit / the answer, 32, is not greater than 255, the largest 8-bit value
Question 2Medium4 marks
A basketball scoreboard stores each team’s score as an 8-bit unsigned binary integer. At half time, the home team has scored 0101 1011 points. In the second half they score another 0011 0110 points.
(a) Calculate the home team’s final score by adding the two binary numbers. Give your answer as an 8-bit binary number.
[2]
(b) Convert your answer to part (a) to denary.
[1]
(c) State the largest score that the scoreboard can store for one team.
[1]
Show the answer and mark scheme
(a) Answer: 1001 0001
  • left-hand four bits: 1001
  • right-hand four bits: 0001
(b) Answer: 145
  • 145
(c) Answer: 255
  • 255
Question 3Hard5 marks
A delivery drone stores its height above the ground, in metres, as an 8-bit unsigned binary integer. The drone is at a height of 1011 0100 metres. It is instructed to climb a further 0101 1010 metres.
(a) Calculate the 8-bit result that will be stored when the two binary numbers are added.
[2]
(b) Explain why this could cause the drone to behave dangerously.
[2]
(c) Give one way the programmers could prevent this problem.
[1]
Show the answer and mark scheme
(a) Answer: 0000 1110 (the carry out of the most significant bit is lost)
  • left-hand four bits: 0000
  • right-hand four bits: 1110
(b) Answer: Overflow: 180 + 90 = 270, but only 14 is stored. The drone believes it is 14 m high and may act on that false height.
  • an overflow has occurred: the true height is 270 m but the stored height is only 14 m
  • the control system would think the drone is close to the ground, so it could make unsafe decisions, e.g. keep climbing / lose track of its real height / fail to avoid obstacles
(c) Answer: Use a 16-bit integer for the height.
  • store the height using more bits, e.g. 16 bits / check for overflow before storing the result / limit the maximum height to 255 m

More in Binary

Stuck? Get 1-to-1 help.

Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.