**⌚ September 17, 2014**

Just as we can perform arithmetic in decimal, we can also perform arithmetic in binary. We will see how to add two binary numbers together.

Though multiple numbers can be added, we will focus on two in order to demonstrate the concept.

Align both numbers vertically from the radix point, and add from right to left. To help avoid mistakes, pad the shorter number with leading zeros. Add numbers the same way as in base 10.

**Add 101b + 10b.**

101. The "." is the radix point. Both are whole numbers. + 010. 10b has been padded to 010b ------- 111b

As a shortcut, there are four possible addition combinations in binary when adding two numbers together.

Rules 1 and 2 are the same as for decimal: 0 + 0 = 0, 0 + 1 = 1, and 1 + 0 = 1. 1 + 1 equals 2, which must be expressed in binary. This is why we see **10b**, not a decimal ten. The 1 occupies the twos place as a carry bit, and the 0 is recorded in the column.

When a bit is carried to a column that already has two ones in it, the fourth combination occurs. 1 + 1 + 1 = 3d, and the binary equivalent of 3d is **11b**, not the decimal eleven. One 1 is recorded in the column, and the other 1 (the most significant bit) is carried tot he next column.

We can add more than two binary numbers together at once just as with decimal, but binary addition is easiest if we add two numbers together at a time.

**Add 101b + 1b.**

Arrange vertically by aligning both numbers by the radix point. If the radix point is absent, align by the least significant bit and use an imaginary radix point. Pad the 1b with leading zeros to avoid errors. Add from right to left.

1 <--- Carry bit because 1 + 1 = 10b 101 + 001 ------- 0 <-- Record the 0 from 10b in the column

Since 1 + 1 = 10, we record the 0 in the ones place and carry the 1 to the next column.

1 101 + 001 ------- 110b

Convert to decimal to confirm that the answer is correct.

101 (5) + 001 (1) --------- 110 (6)

101b (5d) + 1b (1d) equals 110b (6d), so the sum is correct.

**Add 11 + 11b.**

Step 1: Line up the numbers by least significant bit and radix point. 11b (3d) + 11b (3d) --------- Step 2: Add

1 <---- Carry bit 11b (3d) + 11b (3d) --------- 110b (6d)

Column 2 shows the addition of 1+1+1. We record 1 and carry the other 1 to the next column, which creates another place value and results in a sum that is three bits in length, not two.

**Add 10111 + 101b.**

111 <---- Carry bits 10111b (23d) + 00101b ( 5d) -------------- 11100b (28d)

In the second column, we see 1 + 1 + 0. The rule for adding two ones together applies even though a 0 exists. The third column shows another situation where a carry bit adds three ones together.

Here is the procedure:

Step 1: Line up by least significant bit 10111b (23d) + 00101b ( 5d) -------------- Step 2: Add first column. Carry the 1 to the next column.

1 10111 + 00101 ------- 0 Step 3: Add second column: 1 + 1 + 0. Carry the 1 to the third column.

11 10111 + 00101 ------- 00

Step 4: Add the third column: 1 + 1 + 1. Record a 1 and carry a 1.

111 10111 + 00101 ------- 100 Step 5: Add fourth column: 1 + 0 + 0. Nothing to carry, so record 1.

111 10111 + 00101 ------- 1100 Step 6: Add fifth column: 1 + 0 = 1.

111 10111 + 00101 ------- 11100 Answer: 11100b.

## Adding Binary Fractions

Adding binary fractions is the same as adding binary whole numbers. Align both numbers by the radix point, and add from right to left starting at the least significant bit.

**Add 110.1b + 1.001b.**

Line up the numbers by the radix point. We can pad empty space with leading and trailing zeros to help avoid addition mistakes. Each bit must exist in its proper place value.

110.100b + 001.001b ------------ 111.101b

**Add 1001b + 11.0001b.**

11 <--- Carry bits 1001.0000 + 0011.0001 ------------------ 1100.0001

**Add 10.1b + 10.1b.**

Bits carry across the radix point.

1 <--- Carry bit 10.1b + 10.1b --------- 101.0b

## Does 10.1b + 10.1b Really Equal 101.0b?

We can verify binary sums by converting to decimal and performing the same addition in base 10. This works for both whole and fractional binary numbers. Keep in mind that when converting from a decimal fraction to a binary number, the result might not be exact due to limitations with the fractional values available in binary. However, the binary-to-decimal conversion is exact.

**Verify that 10.1b + 10.1b equals 101.0b.**

First, convert the addends to decimal.

10.1b = 2.5d

Then, add in decimal.

2.5 + 2.5 ------- 5.0 = 101.0b

Convert the decimal sum into binary to see if it matches the original binary sum of 101.0b. In this case, it does, so we have verified that 10.1b + 10.1b equals 101.0b (5.0d).

## Practice

As always, practice using pencil and paper.

- 1.0b + 1.1b
- 0.001b + 0.111b
- Verify that 0.001b + 0.111b equals 1.000b by converting and adding in base 10.
- 1010b + 0101b. Verify by converting and adding in base 10.
- 111b + 111b
- 10000b + 111d
- 0.01b + 0.01b
- Convert .010b to decimal.
- Convert 111d to hexadecimal.
- 1100.0011b + 1001.111b. Verify with decimal.

### Answers

- 10.1b (1d + 1.5d = 2.5d)
- 1.000b
- 0.001b = .125d and 0.111b = 0.875d (0.5 + 0.25 + 0.125 = 0.875d), so .125d + .875d = 1.000d.
- 1111b (10d + 5d = 15d)
- 111b + 111b = 1110b
*Ah-ha! Did you catch that?*This is impossible as-is because we are trying to add two different bases together in one operation. Both numbers must be in the same base before addition. We could convert either number to the other base, but since the subject is binary, we will convert 111d to binary, which is 1101111b. Now, we can add 10000b + 1101111b. The answer is 1111111b.*Sneaky, sneaky…*- 0.10b (.25d + .25d = .50d)
- 1/4 or .25
- 0x6f or 6fh or 6f (base 16)
- 10110.0001b

11 11 <--- Carry bits 1100.0011b (12.1875d) + 1001.1110b ( 9.8750d) ------------------------------ 10110.0001b (22.0625d) 10110b = 22d (Whole number part) .0001 = 0.0625 (Fractional part) 22d + .0625d = 22.0625d = 10110.0001b