Fast and easy way to do some multiplications

30 12 2011

Most of computers have the shift left instruction.

Shifting the bits by “x” positions to left, is equivalent to multiplication by x^2.

In this case…

int a = 4;
int b = 0;
b = a<<1;
/* Now, b value is 8 */
b = a<<2;
/* Now, b value is 16 */

That’s all folks!


Actions

Information

Leave a comment