Contents  Mathematics > Binary arithmetic - addition, subtraction, multiplication and division 
 

Simple binary arithmetic (binary addition, subtraction, division and multiplication)

Binary addition:

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10 (carry the 1)

Adding 1 + 1 gives 10, equivalent to decimal 2. This is handled in a similar way to the method used for base 10 when adding; if the result exceeds the radix (10), the left digit is incremented:

8 + 1 = 9
5 + 5 = 10 (= the radix)
8 + 7 = 15 (= radix and 5 more)

In most number systems, when the radix is exceeded, a '1' is carried to the left add the next place value added:

    1 1 1 1 (carry)
    0 1 1 0 1
+   1 0 1 1 1
-------------
= 1 0 0 1 0 0

Starting in the rightmost column, 1 + 1 = 10. The 1 is carried to the left, and the 0 is written at the bottom of the rightmost column. The second column from the right is added: 1 + 0 + 1 = 10 again; the 1 is carried, and 0 is written at the bottom. The third column: 1 + 1 + 1 = 11. This time, a 1 is carried, and a 1 is written in the bottom row. Proceeding like this gives the final answer 100100.

Binary subtraction:

Subtraction is similar:

0 - 0 = 0
0 - 1 = 1 (with borrow)
1 - 0 = 1
1 - 1 = 0

      * * * * (starred columns are borrowed from)
  1 1 0 1 1 1 0
-     1 0 1 1 1
-------------
= 1 0 1 0 1 1 1

Binary multiplication:

Binary multiplication is basically the same as decimal multiplication.

1 * 0 = 0
1 * 1 = 1
1 * 10 = 10
10 * 10 = 100
10 * 100 = 1000
11 * 10 = 110
11 * 11 = 1001

Binary division:

       __________
1 0 1 | 1 1 0 1 1


In the above example the divisor is 101, or 5 decimal, and the dividend is 11011, or 27 decimal. This can be solved with the same long division used for decimal, the divisor 101 goes into the first three digits 110 of the dividend one time, so a "1" is written on the top line. This result is multiplied by the divisor, and subtracted from the first three digits of the dividend; the next digit (a "1") is included to obtain a new three-digit sequence:

                        1
       __________
1 0 1 | 1 1 0 1 1
      - 1 0 1
        -----
          0 1 1


The procedure is then repeated with the new sequence, continuing until the digits in the dividend have been exhausted:

                        1 0 1
       __________
1 0 1 | 1 1 0 1 1
      - 1 0 1
        -----
          0 1 1
        - 0 0 0
          -----
            1 1 1
          - 1 0 1
            -----
              1 0


So the quotient resulting from 11011 divided by 101 is 1012, as shown on the top line, while the remainder, shown on the bottom line, is 102. In decimal, 27 divided by 5 is 5, with a remainder of 2.

Copyright © 2003-2007 Matt Squire. All rights reserved. No content may be duplicated without express written permission.
Hand coded by a thousand monkeys under the direction of Matt Squire
contact: mattsquire at insidereality dot net | Legal stuff

Dude you rock at this game... you have a 100% losing streak...