Number Systems
Data Representation
A computer stores numbers using a fixed number of bits. An 8-bit register can hold values from 0 to 255. An overflow error happens when the result of an addition is too big to fit in the available bits.
How overflow appears in binary addition
Adding 11111111 (255) and 00000001 (1) should give 256. In binary, 256 is 100000000, which is 9 bits long. An 8-bit register can only hold 8 bits, so the leftmost 1 has nowhere to go. The register ends up holding 00000000 and a carry of 1 has been generated out of the most significant bit.
An overflow has occurred when the result of an addition needs more bits than the register can hold, producing a carry out of the leftmost column.
Why overflow matters
If the program does not check for overflow, the carried-out bit is silently lost and the result inside the register is wrong. In safety-critical software (aircraft, medical devices, financial systems), undetected overflow can cause serious failures. Real CPUs set an flag in a status register so that the program can detect and handle it.
Example exam answer for "explain what an overflow error is":
- The result of the calculation is too large to be stored in the available bits.
- A carry is generated out of the most significant bit of the register.
- The stored answer is therefore incorrect.
Common exam question
Adding two 8-bit binary numbers
Question: Add two 8-bit binary numbers using binary addition, giving the answer in binary and showing all your working (3–4 marks).
Asked in 5 of the 17 papers. The marks are split the same way each time: one mark for each correct nibble of the answer and one mark for the working, which means the carries written above the columns. Write every carry down, because the working mark needs them (or another visible method) on the page.
When the two numbers add to more than 255 the question is worth four, and the fourth mark is for identifying the overflow, the final carry out of the leftmost column. Write that 1 as a ninth bit to the left of the eight-bit answer, as the schemes do. Three of the five sums set so far overflowed.
Quick check
4 short questions on this note. See what has stuck, and where to look if something hasn't.