Code for division by 9 in fixed point.
1. q = 0; // quotient
2. y = (x << 3) - x; // y = x * 7
3. while(y) { // until nothing significant
4. q += y; // add (effectively) binary 0.000111
5. y >>= 6; // realign
6. }
7. q >>= 6; // align
Line 2 through 5 in the FIRST execution of while loop
is effectively doing
x*.000111 (in decimal representation x*0.1)
, what it is trying to achieve in subsequent while loops
?
Should it not be again multiplying that with 7 and again shifting instead of doing only shifting to take care of recurrence?
Explanation with respect to plain decimal number multiplication as to what is being achieved with only shifting would be nice.
Detailed code explanation here: Divide by 9 without using division or multiplication operator