Binary Subtraction

http://www.exploringbinary.com/binary-subtraction/


This is the second of a four part series on “pencil and paper” binary arithmetic, which I’m writing as a supplement to my binary calculator. The first article discusses binary addition; this article discusses binary subtraction.

An Example of Binary Subtraction

Example of Binary Subtraction

The pencil-and-paper method of binary subtraction is just like the pencil-and-paper method of decimal subtraction you learned in elementary school. Instead of manipulating decimal numerals, however, you manipulate binary numerals, according to a basic set of rules or “facts.”

Decimal Subtraction

For decimal subtraction, the basic facts are things like 5 – 1 = 4, 9 – 8 = 1, and 18 – 9 = 9. In each case, the answer is a single-digit, nonnegative integer. Most of the facts are “single-digit minus single-digit” problems, but some are “double-digit minus single-digit” problems (the double digits are the numbers 10 through 18). The latter represent cases of borrowing, which is the process by which negative answers are prevented.

Here’s an example of decimal subtraction:

An Example of Decimal Subtraction

Example of Decimal Subtraction

After the points are aligned, subtraction proceeds from right to left. Red marks indicate borrowing. If a non-zero digit is borrowed from, it is crossed out, one is subtracted from it, and the decremented digit is written above it; a 1 is then placed next to the digit in the borrowing position, making it a two-digit number. If a zero digit is borrowed from, the borrow “cascades” until a non-zero digit is found.

Here’s the example again, step-by-step:

Steps of Decimal Subtraction

Steps of Decimal Subtraction

  • Step 1: 5 – 0 = 5.
  • Step 2: Borrow to make 12 – 5 = 7.
  • Step 3: Borrow to make 15 – 7 = 8.
  • Step 4: Borrow to make 10 – 1 = 9.

Some people refer to this as the “American method” (although this is just one variation of it — see Salman Khan’s video, for example). Whatever your method is though, you can apply it to binary numbers.

Binary Subtraction

For binary subtraction, there are four facts instead of one hundred:

  • 0 – 0 = 0
  • 1 – 0 = 1
  • 1 – 1 = 0
  • 10 – 1 = 1

The first three are the same as in decimal. The fourth fact is the only new one; it is the borrow case. It applies when the “top” digit in a column is 0 and the “bottom” digit is 1. (Remember: in binary, 10 is pronounced “one-zero” or “two.”)

Now let’s subtract 1011.11 from 10101.101, following the same algorithm I used for decimal numbers:

Steps of Binary Subtraction

Steps of Binary Subtraction

  • Step 1: 1 – 0 = 1.
  • Step 2: Borrow to make 10 – 1 = 1.
  • Step 3: Borrow to make 10 – 1 = 1.
  • Step 4: Cascaded borrow to make 10 – 1 = 1.
  • Step 5: 1 – 1 = 0.
  • Step 6: 0 – 0 = 0.
  • Step 7: Borrow to make 10 – 1 = 1.

Since there are lots of 0s in binary numbers, there can be lots of borrows — and lots of messy looking cross-outs.

Checking the Answer

You can check the answer in a few ways. One way is to add the result (1001.111) to the subtrahend (1011.11), and check that that answer matches the minuend (10101.101):

Check Binary Subtraction Using Binary Addition

Check Binary Subtraction Using Binary Addition

Another way is to convert the operands to decimal, do decimal subtraction, and then convert the decimal answer to binary. 10101.101 = 21.625 and 1011.11 = 11.75, and 21.625 – 11.75 = 9.875. 9.875 = 1001.111, the answer we got using binary subtraction.

You can also check the answer using my binary calculator.

Subtracting a Bigger Number From a Smaller Number

To subtract a bigger number from a smaller number, just swap the numbers, do the subtraction, and negate the result.

Discussion

Notice that I didn’t discuss the number base when describing the algorithm; it is base-independent. Nonetheless, I could have talked about powers of ten and powers of two, and how the process can be visualized by regrouping. My goal was to explain just the mechanized algorithm (presumably you do decimal subtraction mechanically, no longer thinking about why it works).

Subtracting Using Complements

Computers don’t subtract this way; they subtract by adding complements. It’s more efficient. You can do subtraction by complements with pencil-and-paper, but you won’t find it more efficient. (In decimal, you would use nine’s complement or ten’s complement; in binary, you would use ones’ complement or two’s complement.)

Dingbat

11 Responses to “Binary Subtraction”

  1. kavita krishnan Says:

    SIMPLE & EASY. TOO GOOD.

  2. sushant Dev Singh Says:

    I was not able to learn binary subtraction without this site thanks a lot.

  3. Hayden Caleb Llewellyn Says:

    Now I know.

  4. K.K.Narayanan Says:

    Very simple and very easy to understand.
    Thanks

  5. jay ann castañares Says:

    what will happen if the last digit in the left side is 0..i mean there is nothing left to borrow? is there any rule about it?

  6. Rick Regan Says:

    @jay ann,

    Are you talking about subtracting a bigger number from a smaller number? As I mentioned in the article, just swap the numbers, do the subtraction, and negate the result.

  7. pritam Says:

    Why 0- 1 =1 in binary

  8. pritam Says:

    Please explain its theory…soon

  9. Rick Regan Says:

    @pritam,

    0-1 = -1 in binary.

  10. Suyash Says:

    Your method rocks!!!

  11. paul Says:

    thanks a lot :) Really helps . Keep the good work going :D

Leave a Comment

(To reduce spam, cookies must be enabled)


css.php