Adding Binary Numbers
Overflow happens when the result of an addition is too large for the number of bits available to store it. An unsigned 8-bit pattern holds values from 0 to 255, so a total of 256 or more cannot be stored in one byte.
Adding two positive 8-bit patterns can need a ninth bit. It appears as a carry out from the most significant bit (the 128 column), and eight bits have nowhere to keep it.
For example, a ticket counter in one byte records 200 tickets, then 100 more.
| Place value | Carry out | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|---|
| Carry in | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| First number (200) | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | |
| Second number (100) | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | |
| Result bits | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 |
The 128 column is 1 + 0 + 1 = 0 with a carry out of 1, so the full sum is 1 00101100 (300). Stored in eight bits, only 00101100 (44) remains. That is an overflow error: the result cannot be correctly represented in the fixed number of bits.
If no carry leaves the 128 column, the total fits in eight bits. For example, 01011010 (90) plus 01111000 (120) gives 11010010 (210), so no overflow. A sum within 0 to 255 is safe; one above 255 overflows.
The addition itself is correct; overflow is caused by the fixed width. If you are asked for the result of the addition, include the ninth bit; if the value must be stored in eight bits, report overflow.
Edexcel GCSE Computer Science · Adding Binary Numbers