Division of binary numbers is simpler than division of decimal numbers.
Let us extend to a fractional binary representation with the point (or comma) separating powers of 2 with positive and negative exponents, so that e g
- 110.11 thus represents
decimal.
Division by the binary number is done by shifting the point one step to the left.
Division by the binary number is done by shifting the point two steps 0 to the left.
Division by the binary number 1 followed by k zeros is done by shifting the point k steps to the left.
Let a be binary number named dividend to be divided by another (non-zero) binary number b named divisor to give the quotient q=a/b.
The digits of the quotient q can be computed successively from left with first non-zero digit equal to the digit of the largest one-digit number d such that
- d*b <a.
Then replace a by latex a-d*b and repeat the process to find the next non-zero digit of the quotient, and so on. This procedure is called long division.
To do:
- Write a code implementing binary long division.
- Hint: Check this code