Sunday, January 13, 2008

Integer Division by 7 Trick

Q:How to make an integer division by 7 faster?

No closed discussion found so far.
As I was wondering: the following pieces of pseudo codes might perform well

x = x>>3 + x>> 6 + x>> 9 + x>>12 + x >> 15 .....+ (increase i by 3 until x >> i becomes zero)

since it is an integer operation, we are not really looking at the exact value. The logic behind this is approximation.
To notice: x/7 = x/8 + x /7*8 = x/8 + x/8*8 + x/7*8*8 = x /8 + x/8*8 + x/8*8*8 + x/7*8*8*8......

No comments: