How can I use bit shifting to replace integer division?
I understand how to do it for powers of 2 so that's not my question. For example, if I want to find 5% of a number using a bit shift instead of an integer divide, how would i calculate that? So instead of (x * 20 / 19), I could do (x * 100 >> 11). Now this isn't right but it's close and I arrived at it using trial and error. How would I determine the most possible precise shift to use? High Performance Mark Best approach is to let the compiler do it for you. You simply write a/b in your language of choice, and the compiler generates the bit twiddling. EDIT (I hope you don't mind, i'm adding