In the previous article, we have already discussed the Non-Restoring Division Algorithm. In this article, we will discuss the implementation of this algorithm.
Non-restoring division algorithm is used to divide two unsigned integers. The other form of this algorithm is Restoring Division. This algorithm is different from the other algorithm because here, there is no concept of restoration and this algorithm is less complex than the restoring division algorithm. Let the dividend Q = 0110 and the divisor M = 0100. The following table demonstrates the step by step solution for the given values:
|Operation:A – M||1011||1110||Unsuccessful(-ve)
A+M in Next Step
|Operation:A + M||1100||1100||Unsuccessful(-ve)
A+M in Next Step
|Operation:A + M||1110||1000||Unsuccessful(-ve)
A+M in Next Step
|Operation:A + M||0010||0001||Successful(+ve)|
Approach: From the above solution, the idea is to observe that the number of steps required to compute the required quotient and remainder is equal to the number of bits in the dividend. Initially, let the dividend be Q and the divisor be M and the accumulator A = 0. Therefore:
- At each step, left shift the dividend by 1 position.
- Subtract the divisor from A (A – M).
- If the result is positive then the step is said to be “successful”. In this case, the quotient bit will be “1” and the restoration is NOT Required. So, the next step will also be subtraction.
- If the result is negative then the step is said to be “unsuccessful”. In this case, the quotient bit will be “0”. Here, the restoration is NOT performed like the restoration division algorithm. Instead, the next step will be ADDITION in place of subtraction.
- Repeat steps 1 to 4 for all bits of the Dividend.
Below is the implementation of the above approach:
Initial Values: A: 0000 Q: 0111 M: 0101 step: 1 Left Shift and subtract: A: 1011 Q: 111_ -Unsuccessful A: 1011 Q: 1110 -Addition in next Step step: 2 Left Shift and Addition: A: 1100 Q: 110_ -Unsuccessful A: 1100 Q: 1100 -Addition in next Step step: 3 Left Shift and Addition: A: 1110 Q: 100_ -Unsuccessful A: 1110 Q: 1000 -Addition in next Step step: 4 Left Shift and Addition: A: 0010 Q: 000_ Successful A: 0010 Q: 0001 -Subtraction in next step Quotient(Q): 0001 Remainder(A): 0010
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Implementation of Restoring Division Algorithm for unsigned integer
- Restoring Division Algorithm For Unsigned Integer
- Non-Restoring Division For Unsigned Integer
- Find Quotient and Remainder of two integer without using division operators
- Trial division Algorithm for Prime Factorization
- Minimum decrements to make integer A divisible by integer B
- Multiply two integers without using multiplication, division and bitwise operators, and no loops
- Write you own Power without using multiplication(*) and division(/) operators
- DFA based division
- Modular Division
- Program to compute division upto n decimal places
- Division without using '/' operator
- Trick for modular division ( (x1 * x2 .... xn) / b ) mod (m)
- Divide two integers without using multiplication, division and mod operator | Set2
- Find the number after successive division
- Number of digits before the decimal point in the division of two numbers
- Maximum value of division of two numbers in an Array
- Check if it is possible to perform the given Grid Division
- Long Division Method to find Square root with Examples
- Maximize the division result of Array using given operations
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.