Adding Binary Numbers
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.
| Bits being added | Result bit | Carry |
|---|---|---|
| 0 + 0 | 0 | 0 |
| 0 + 1 | 1 | 0 |
| 1 + 0 | 1 | 0 |
| 1 + 1 | 0 | 1 |
| 1 + 1 + 1 | 1 | 1 |
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.
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:
| Row | Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
|---|---|---|---|---|---|---|---|---|
| Carry in | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| First number | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 0 |
| Second number | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
| Answer | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
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.
OCR GCSE Computer Science · Adding Binary Numbers