Menu

Binary

Adding Binary Numbers

Contents

  1. Adding Binary Numbers
  2. Overflow in Binary Addition

Adding two binary numbers works in the same way as column addition with denary: write the numbers one above the other so the place values line up, then add one column at a time, starting at the rightmost bit (the 1s column) and moving left.

The rules for a single column

Each column holds only 1s and 0s, so there are just four single-bit cases when nothing is carried in. The answer to 1 + 1 is the surprising one: you cannot write 2 in binary, so the column drops back to 0 and you carry 1 into the column on its left, where it is worth 2.

Bits in the columnWrite downCarry to the next column left
0 + 000
0 + 110
1 + 010
1 + 101
1 + 1 + 111

The last row matters because a column may already have a carry sitting above it, giving three bits to add. Work through it: 1 + 1 makes 0 carry 1, and adding the third 1 turns that 0 back into 1, still carrying 1.

Keeping track of carries

Write each carry in a row above the numbers, positioned over the next column to the left, so you cannot forget it. If a carry travels through several columns in a row, the row above fills with 1s, and each of those columns needs its carry included when you add it.

A worked 8-bit example

Add 01011010 (90) and 00110110 (54), using the place values 128 down to 1 as the column headings.

Row1286432168421
Carry11111100
Number A01011010
Number B00110110
Result10010000

Column addition of 01011010 and 00110110 under place values 128 to 1, with a carry row and arrows moving each carry one column left. The result row is 10010000, which is 144.

Reading the result row gives 10010000, which is 128 + 16 = 144. The denary check confirms it, because 90 + 54 = 144. Converting your answer back to denary like this is the quickest way to spot a carry you missed.

A carry leaving the 128 column has no column of its own inside eight bits; that situation is called overflow and is covered in 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.

Also useful