Menu

Adding Binary Numbers

Overflow in Binary Addition

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.

Carry out of the most significant bit

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 valueCarry out1286432168421
Carry in10000000
First number (200)11001000
Second number (100)01100100
Result bits100101100

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.

Addition of 200 and 100 in eight columns with a carry in at the 128 column. The result bits are 00101100 (44) and a ninth carry-out bit is marked as overflow because it has no room.

Results that fit

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.

Practise this