Re:Absolute Beginner's Guide to Bit Shifting
by pjscott on Sunday March 04, 2012 @04:37PM
(#3664110)
Here's an article explaining the trick:
http://ridiculousfish.com/blog/posts/labor-of-division-episo...
And a library from the same guy for generating code at runtime to do fast division by constants:
Incidentally there is a standard trick for integer division by constant which allows you to convert it into a series of 3 to 5 shift and add/subtract operations; any decent C compiler will implement this. _Hacker's Delight_ has the explanation of the algorithm, I think.