Menu

Memory & Storage

Adding Binary Numbers

Contents

  1. Adding Binary Numbers
  2. Checking Binary Addition
  3. Binary Overflow

Adding two binary numbers uses the same column method as adding denary numbers, but each column can hold only 0 or 1. When a column adds up to 2 or more, the value will not fit in one bit, so a carry of 1 moves into the next column on the left. Every sum here adds two positive integers of up to 8 bits: there is no subtracting and no negative numbers.

The addition rules

Bits being addedResult bitCarry
0 + 000
0 + 110
1 + 010
1 + 101
1 + 1 + 111

The last row happens when a carry lands in a column that already holds 1 + 1. Three ones make denary 3, which is 11 in binary, so you write 1 and carry 1. Because only bits with the same place value share a column, the two numbers are lined up from the right-hand end. If they are different lengths, pad the shorter one with leading zeros on the left until both have the same number of bits, up to 8; to add 0110 and 101, write the second number as 0101.

Working through a sum

Work from the far-right column, which holds the least significant bit, leftwards one column at a time. In each column add the two bits and any carry arriving from the right, write the result bit in the answer row, then record any new carry above the column to its left. Here is 01001110 + 00110101:

RowBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
Carry in11111000
First number01001110
Second number00110101
Answer10000011

At bit 0, 0 + 1 = 1 with no carry. At bit 2, 1 + 1 = 0 carry 1, and that carry keeps rippling leftwards until bit 7, where 0 + 0 + 1 = 1. The final answer is written as an 8-bit binary number underneath the calculation: 10000011.

Show every carry clearly, placed on the correct column, because marks are awarded for the carry working as well as the answer; a carry can go above or below the numbers as long as it is on the right column. A carry leaving the leftmost column cannot be stored in 8 bits - that is covered in Binary Overflow.

Once you have worked out an 8-bit binary addition, you can check it by converting the two numbers and your answer into denary. As long as the exact total is 255 or less, the two denary values should add up to the denary value of your answer. If they do, the binary result is correct.

A worked check

Suppose you add 0110 and 0011 and your column working gives 1001. To check it:

  • 0110 is 6 in denary.
  • 0011 is 3 in denary.
  • 6 + 3 = 9.
  • Your answer, 1001, is 8 + 1 = 9.

Both sides give 9, so the answer fits. If you had written 1000 instead, that is 8, and the check would compare 9 with 8 and fail. The slip is usually a carry missed from the next column, including the final carry into the most significant bit, so go back through the columns rather than changing the answer to fit. The same method works for 8-bit numbers: convert both inputs and your answer to denary and check that the sum of the inputs equals the denary value of your answer, provided the sum is no more than 255.

The check is not the working

Converting and adding in denary only ever confirms a result. It never shows column addition: no carries appear above or below the digits and no column is worked through, so it cannot earn the mark for showing your method. Adding the two denary values and converting the total back into binary may land on the right answer, but it is not accepted as working.

Denary checkBinary column addition
What it doesconfirms a result you already haveproduces the result
Shows carriesnoyes
Earns the working marknoyes

When the denary total is too big

Eight bits can store denary values from 0 to 255 only. If your two denary values add up to more than 255, the exact total needs a ninth bit, so your 8-bit answer will not match the denary total. That is an overflow, not a slip in your columns: give the 8-bit result and state that an overflow has occurred.

An overflow occurs when a calculation produces a result that is larger than the maximum value that can be represented using the available bits. With 8 bits, the largest value you can store is 255, which is 11111111 in binary, so any total from 256 upwards cannot be held in 8 bits.

Why the ninth bit is lost

Suppose an 8-bit game score holds 186 points (10111010) and a player earns 103 more points (01100111). The true total is 289, so it needs nine bits.

Column76543210
First number10111010
Second number01100111
Carry in11111100
Result bit00100001

Adding the columns produces a carry out of column 7, so the nine-bit total is 100100001. The bit in column 7 is the most significant bit, and the 1 that leaves it has nowhere to go, so it is lost. The 8 bits left behind are 00100001, which is 33, not 289. The stored result is wrong by 256, the value of the lost ninth bit.

Overflow can come from a carry

Overflow happens when a carry leaves the most significant column. That occurs when both leftmost bits are 1, and also when a carry arrives into the leftmost column while one of the two leftmost bits is a 1, as in the score example, where column 7 works out as 1 + 0 + 1: a result bit of 0 with a carry out.

Showing an overflow

When you add two 8-bit numbers and the total is above 255, give the 8-bit binary result, show that the ninth bit has been produced and lost (for example, write it and cross it out), and state that an overflow has occurred. If a program does not deal with an overflow, it may carry on with the wrong value and produce incorrect output, or it may crash.