You may notice that when you divide num by 10 you get a quotient q and a remainder r:
num = q*10 + r
Once you get q, you can solve for r as r = num - q*10
So this is how you get r and q: q = (num >> 1) + (num >> 2);
q = q + (q >> 4);
q = q + (q >> 8);
q = q + (q >> 16);
q = q >> 3;
r = num - q*10;
q = q + ((r + 6) >> 4)
voila!