Binary Arithmetic!

It all adds up.

Introduction

In this final section of the Binary Tutorial you will learn how to easily perform binary arithmetic (addition, subtraction, multiplication and division) by hand.

Binary arithmetic is one of those skills which you probably won't use very often. It can be very useful to know however. These processes are often stepping stones to more complex processes which can do very powerful things. Fortunately, they are not too difficult so with a bit of practice you'll be off and running in no time.

There are many calculators now which can do binary arithmetic for you. Just about every desktop OS, smart phone and tablet has one built in or one can easily be aquired. It is perfectly fine to use the calculator but we should know how to do it by hand as well. This will give us a much better understanding as to what is actually happening. That understanding is important in order to understand how certain mechanisms work (especially in computing). My recommnedation is to practice on paper by hand but use the calculator to verify your working.

Note: For educators, the interactive examples work well for demonstrations on a projector or smart board.

Binary Addition

Binary addition is the easiest of the processes to perform. As you'll see with the other operations below, it is essentially the same way you learnt to do addition of decimal numbers by hand (probably many years ago in your early school years). The process is actually easier with binary as we only have 2 digits to worry about, 0 and 1.

The process is that we line the two numbers up (one under the other), then, starting at the far right, add each column, recording the result and possible carry as we go.

Here are the possibilities:

  • 0 + 0 = 0
  • 1 + 0 = 1
  • 1 + 1 = 2 which is 10 in binary which is 0 with a carry of 1
  • 1 + 1 + 1 (carry) = 3 which is 11 in binary which is 1 with a carry of 1

The carry is involved whenever we have a result larger than 1 (which is the largest amount we may represent with a single binary digit).

Here is an example:

(Note: The colour of the digits is only to help in aligning them up.)

(Note: To see the next step you may click the button 'Next Step' or click/ tap anywhere in the example area. Applies to this example and all the examples below.)

Adding more than two numbers

It is possible to add more than 2 binary numbers in one go but it can soon get unweildly managing the carries. My suggestion is that you add the 1st and 2nd numbers together. Then take the result and add the third number to that. Then take the result and add the 4th etc. This way you may add as many binary numbers as you like and the complexity will never increase. It's a little more work but with practice you will get very quick at it.

Binary Multiplication

Binary multiplication is just about as easy as binary addition. Again it is the same process as we would do with decimal multiplication by hand. Again it is easier as binary only has 0 and 1.

We line the two numbers up (similar to addition). Then we multiply the entire top number by each individual digit of the bottom number. As we move across each digit we pad out the result with 0's to line it up. Finally we add all the results together.

Here are the possibilities:

  • 0 * 0 = 0
  • 1 * 0 = 0
  • 1 * 1 = 1

Can't get much easier than that can it?

Here is an example:

As you have no doubt noticed, the process is fairly straight forward. If the binary digit on the second row we are multiplying by is a 1 then pad out accordingly and write out the top binary number. If the binary digit on the second row we are multiplying by is a 0 then we can just write out 0's.

If we want to multiply a binary number by another number which is a power of 2 then all we need to do is add the number of 0's representing that power to the right of the first number.

eg. 8 is 23 which is 1000 in binary.

101101 x 1000 = 101101000

Binary Subtraction

With binary subtraction we start to get a little more difficult (But not that difficult). Similar to binary addition, we will work through the numbers, column by column, starting on the far right. Instead of carrying forward however, we will borrow backwards (when necessary).

Here are the possibilities:

  • 0 - 0 = 0
  • 1 - 0 = 1
  • 1 - 1 = 0
  • 0 - 1 we can't do so we borrow 1 from the next column. This makes it 10 - 1 which is 1.

Here is an example:

If we have multiple 0's in a row on the top number and need to borrow then things get a little interesting. It follows this general process:

Let's say we have 100 - 1

  • In the first column we need to borrow a 1 but the second column is 0.
  • Column 2 borrows a 1 from the third column and becomes 10 (2 in decimal)
  • Now we may borrow 1 from the second column (decreasing it from 2 to 1 or from 10 to 1)
  • Now column 2 is 1 and column 1 is 10 and we may continue as normal.

Sometimes you may have to do this over multiple columns but the process is the same.

Another approach

The above example is the most convenient way for us to do binary subtraction by hand. There is another approach however and this is the way that computers subtract binary digits. This approach is called Two's Complement.

Let's say we want to compute 1000 ( 8 ) - 11 ( 3 ).

  • Step 1: Write the equation out, padding the bottom number with 0's
    1000
    0011 -
  • Step 2: Invert the digits of the lower number
    1000
    1100
  • Step 3: Add 1 to the lower number
    1000
    1101
  • Step 4: Add those two numbers together to get 10101
  • Step 5: Remove the leading 1 (and any 0's after it). You are left with 101 ( 5 ).

Binary Division

Binary division is probably the most difficult of the binary equations. Fortunately, it is also made easier by the fact we only have to deal with 1's and 0's.

First off, some terminology. The number we are dividing by is the divisor. The number we are dividing into is the dividend.

The process is as follows:

  • Step 1: Create the working portion of the dividend. Starting at the right, keep including digits until we have a number that the divisor will go into.
  • Step 2: Work out how many times the divisor goes into the working portion (with binary this is easy as it will always be 1). Write this number above the line (in line with the far right digit of the working number).
  • Step 3: Subtract the divisor from the working number. This becomes the beginning of the new working number.
  • Step 4: Bring down digits from the dividend and add to the new working number until we have a new working number large enough for the divisor to go into.
  • Step 5: Repeat steps 2 to 4 until we are at the end of the dividend.
  • Step 6: The result of the final subtraction is the remainder.

Well that was quite a bit to take in wasn't it. Let's look at an example to clear things up:

Advice

This stuff can be a little hard to get your head around. If you find reading through the material doing your head in a bit here's what I suggest:

  • Generate a few different sets of numbers in the examples above for the operation you are having trouble with. Often the process get's clearer after you've seen it demonstrated a few times.
  • For smaller numbers (5 digits or less) get in the habit of mentally converting them to decimal (eg. for 101 you can say: "Ah that's 1 plus 0 plus 4 which is 5"). This helps give them meaning rather than just being abstract things you'r performing random actions on.
  • Work through several activities below on paper. Learning binary is kinda like riding a bike. The best way is just to do it.
  • Leave it a day or two then come back and have another go.

Activities

So the best way to learn this stuff is to practice it and now we'll get you to do just that. For each of the activities below you can keep generating new numbers to try so keep working through them until you you're comfortable with them.

  • Binary addition:
  • Binary multiplication:
  • Binary subtraction:
  • Binary division:

It may help to convert the numbers (working numbers and answer) to decimal after doing your working to confirm it is correct. (as opposed to just plugging it into a calculator)