In the previous article, we have already discussed the Restoring Division Algorithm. In this article, we will discuss the implementation of this algorithm.
Restoring Division Algorithm is used to divide two unsigned integers. This algorithm is used in Computer Organization and Architecture. This algorithm is called restoring because it restores the value of Accumulator(A) after each or some iterations. There is one more type i.e. Non-Restoring Division Algorithm in which value of A is not restored. Let the dividend Q = 0110 and the divisor M = 0100. The following table demonstrates the step by step solution for the given values:
|Step 1: Left-Shift||0000||110_|
|A – M||1100||Unsuccessful(-ve)|
|Step 2: Left-Shift||0001||100_|
|A – M||1101||Unsuccessful(-ve)|
|Step 3: Left-Shift||0011||000_|
|A – M||1111||Unsuccessful(-ve)|
|Step 4: Left-Shift||0110||000_|
|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.
- If the result is negative, then the step is said to be unsuccessful. In this case, the quotient bit will be “0” and restoration is required.
- Repeat the above steps for all the bits of the dividend.
Note: Here, restoration is performed by adding back the divisor to A.
Initial Values: A: 0000 Q: 0110 M: 0100 step: 1 Left Shift and Subtract: A: 1100 A: 1100 Q: 110_ -Unsuccessful A: 0000 Q: 1100 -Restoration step: 2 Left Shift and Subtract: A: 1101 A: 1101 Q: 100_ -Unsuccessful A: 0001 Q: 1000 -Restoration step: 3 Left Shift and Subtract: A: 1111 A: 1111 Q: 000_ -Unsuccessful A: 0011 Q: 0000 -Restoration step: 4 Left Shift and Subtract: A: 0010 A: 0010 Q: 000_ Successful A: 0010 Q: 0001 -No Restoration 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 Non-Restoring Division Algorithm for Unsigned Integer
- Find Quotient and Remainder of two integer without using division operators
- Trial division Algorithm for Prime Factorization
- Exact Cover Problem and Algorithm X | Set 2 (Implementation with DLX)
- Prim's Algorithm (Simple Implementation for Adjacency Matrix Representation)
- Minimum decrements to make integer A divisible by integer B
- Cyclic shifts of integer N by another integer m
- 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
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.
Improved By : amit_mangal_