How to divide binary numbers: 13 steps (with pictures)

How to divide binary numbers: 13 steps (with pictures)
How to divide binary numbers: 13 steps (with pictures)
Anonim

Problems with dividing binary numbers can be solved using the long division method, a useful method for learning this process or creating a simple program on a computer. Otherwise, the complementary method of successive subtraction provides an approach that you may not be familiar with, although it is commonly used in programming. Machine language generally uses an estimation algorithm for greater efficiency, but we will not describe these here.

Steps

Method 1 of 2: Use the long division method

Divide Binary Numbers Step 1

Step 1. Review the method of long division with decimals

If you haven't used the long division method with ordinary decimals (in base 10) for a long time, then review your bases using the following example: 172 ÷ 4. Otherwise, skip this step and go to following to learn the same process applied to binary numbers.

  • the dividend is divided by the divider and the result of this operation is the quotient.
  • Compare the divisor to the first digit of the dividend. If the divisor is greater than the latter, keep adding tens to the dividend until the divisor becomes less. For example, in the following division: 172 ÷ 4, we would have to compare 4 and 1, notice that 4> 1 and then compare 4 to 17 instead.
  • Write the first digit of the quotient above the last digit of the dividend you used in the comparison. By comparing 4 and 17, we notice that the number 4 multiplied by 4 gives a result less than 17. We therefore write 4 as the first number of our quotient, above the 7.
  • Perform multiplication and subtraction to find the remainder. Multiply the number of the quotient by the divisor, that is in our case 4 x 4 = 16. Write the 16 under 17, then subtract 16 - 17 to find the remainder, that is to say 1.
  • Repeat the operation. Once again, we need to compare the divisor (4) with the next digit (1), notice that 4> 1, and “roll back” the next digit of the dividend to compare 4 with 12 this time around. 4 is multiplied by 3 to give 12 and there is nothing left. So the next number to write for the quotient is 3. The answer is 43.
Divide Binary Numbers Step 2

Step 2. Write your problem as a long division

Let's use the following example: 10 101 ÷ 11. Write this as a long division, with 10 101 for the dividend and 11 for the divisor. Leave a space to write the quotient and write your calculations below.

Divide Binary Numbers Step 3

Step 3. Compare the divisor to the first digit of the dividend

It works like a long division with decimals, but it's actually a bit easier. Either you cannot divide the number by the divisor (0), or you can divide it once by the divisor (1):

11> 1, so you cannot divide 1 by 11. Write 0 as the first digit of the quotient (above the first digit of the dividend)

Divide Binary Numbers Step 4

Step 4. Go to the next number and repeat the operation until you get a 1

Here are some steps of our example:

  • bring back the next dividend digit. 11> 10. Write 0 in the quotient
  • bring back the next digit. 11 <101. Write 1 in the quotient
Divide Binary Numbers Step 5

Step 5. Find the rest

As for the long divisions of decimals, we must multiply the figure we have just found (either 1) by the divisor (or 11) and write the result under the dividend, aligned with the figure with which we have just made our calculation. With binary numbers, we can skip this step, because 1 multiplied by the divisor gives the divisor.

  • Write the divisor under the dividend. In our case, we align 11 under the first three digits (i.e. 101) of the dividend.
  • Calculate 101 - 11 to get the remainder, which is 10.
Divide Binary Numbers Step 6

Step 6. Repeat the operation until you have completed the division

Combine the next digit of the divisor with the remainder to get 100. Since 11 <100, write 1 as the next digit of the quotient. Continue dividing as before.

  • Write 11 under the number 100 and do a subtraction to get 1.
  • Bring back the last digit of the dividend to get 11.
  • 11 = 11, then write 1 as the final number of the quotient (the result).
  • There is no remainder, so the division is complete. The answer is 00111 or simply 111.
Divide Binary Numbers Step 7

Step 7. Add a comma if necessary

Sometimes the result is not an integral number. If you still have a remainder after adding the last digit, add a comma followed by a zero (", 0") to the dividend and a comma (",") to your quotient, so that you can bring another digit down and continue.. Repeat this process until you have reached the desired level of precision, then round off your result. On paper, you can round off the result by removing the last 0 or, if the last digit is a 1, drop it and add 1 to the new last digit. In programming, follow one of the standard algorithms for rounding to avoid making mistakes when converting between binary numbers and decimals.

  • Divisions of binary numbers often end with a series of repeating fractions, more often than with decimal entries.
  • This refers to the use of the term “binary comma”, equivalent to the classic comma used in the decimal system.

Method 2 of 2: Use the two's complement method

Divide Binary Numbers Step 8

Step 1. Understand the basic concept

One way to solve the divisions (regardless of the base considered) is to keep subtracting the divisor from the dividend, then the rest, while counting the number of times you can do it before you get a negative number. Here is an example in base 10, to solve the division 26 ÷ 7:

  • 26 - 7 = 19 (subtracted 1 time),
  • 19 - 7 = 12 (2),
  • 12 - 7 = 5 (3),
  • 5 - 7 = -2. You get a negative number, which is why you have to retrace your steps. The answer is 3 and the remainder is 5. Note that this method does not calculate the non-integer parts of the result.
Divide Binary Numbers Step 9

Step 2. Learn to subtract by two's complement

If you can easily employ the above method with binary numbers, you can subtract using a more efficient method that will save you time when programming computers to divide binary numbers. This is the two's complement subtraction method. Here are the basics, for calculating 111 - 011 (make sure both numbers are the same length).

  • Find the complement of the second term, subtracting each digit from 1. It's easy to do with binary numbers. It suffices to replace the 1 by 0 and the 0 by 1. In our example, 011 becomes 100.
  • Add 1 to the result: 100 + 1 = 101. This is called the two's complement method and it can be used to perform subtractions as well as additions. After all, it's basically like we added a negative number instead of subtracting a positive number.
  • Add the result with the first number. Write and solve the addition: 111 + 101 = 1,100.
  • Remove the retainer. Discard the first digit of your answer to get the final result. 1,100 → 100.
Divide Binary Numbers Step 10

Step 3. Combine the two previous concepts

Now that you know the subtraction method to solve long divisions as well as the two's complement method to solve subtraction, you can combine these two methods to solve division problems by following the steps below. If you want, you can try to figure it out for yourself before continuing.

Divide Binary Numbers Step 11

Step 4. Subtract the divisor from the dividend, adding two complements

Take for example the division 100 011 ÷ 000 101. The first step consists in solving the operation 100 011 - 000 101, which we will transform into addition using the two complements method:

  • two complements of 000 101 = 111 010 + 1 = 111 011
  • 100 011 + 111 011 = 1 011 110
  • remove the retainer → 011 110
Divide Binary Numbers Step 12

Step 5. Add 1 to the quotient

When writing a program, this is where you will start to increment the 1 to 1 quotient. Write it down somewhere in the corner of a sheet of paper so you don't mix it up with other work. We managed to do a first subtraction, so the quotient is 1.

Divide Binary Numbers Step 13

Step 6. Repeat the process, subtracting the divisor from the remainder

The result of our last calculation is the remainder after the divisor has been "placed" once. Continue to add the two divider's complements each time and remove the retainer. Add 1 to the quotient each time and repeat until you get a remainder that is equal to or less than your divisor:

  • 011 110 + 111 011 = 1 011 001 → 011 001 (quotient 1 + 1 = 10)
  • 011 001 + 111 011 = 1 010 100 → 010 100 (quotient 10 + 1 = 11)
  • 010 100 + 111 011 = 1 001 111 → 001 111 (11+1=100)
  • 001 111 + 111 011 = 1 001 010 → 001 010 (100+1=101)
  • 001 010 + 111 011 = 10 000 101 → 0 000 101 (101+1=110)
  • 0 000 101 + 111 011 = 1 000 000 → 000 000 (110+1=111)
  • 0 is smaller than 101, so we stop there. The quotient 111 is the result of division. The remainder is the end result of our subtraction and is therefore equal to 0 (so there is nothing left).

Advice

  • You should review the instructions for incrementing, decrementing, or unstacking data before applying binary math operations to a machine's instruction set.
  • Disregard the signed digit in the signed binary numbers before doing your calculation, except when determining whether the result is positive or negative.
  • The two's complement subtraction method will not work if your numbers do not have the same number of digits. Add zeros at the start of the shorter number to remedy this.

Popular by topic