Fast multiplicationThis tip submitted by Jean-François Geyelin on 2005-03-01 05:54:49. It has been viewed 46607 times.
Rating of 6.7 with 261 votes
It is well known that bit shifting enables programmers to do multiplication when dealing with numbers such as 2, 4, 8, 16, 32, 2^n, ...
But multiplying by 100 (and for many other numbers) is also possible:
a= a*64 + a*32 + a*4;
Some compilers might optimise this by themselves.
Finally, when dealing with floats, you can also do fast multiplications by 2,4,5,6 (or by 10,100,1000 depending on the internal representation of the floats) simply by increasing/decreasing the exponent.
Help your fellow programmers! Add a tip!