division and multiplication by power of 2
I read in a paper that division and multiplication of a number by a power of 2 is a trivial process. I have searched a lot of internet for the explanation but doesn't get it. Can any one explain in easy words what does this actually meant to say. Vlad It is trivial from the bit operations perspective. Multiplying by 2 is equivalent to a shift left by 1 bit, division is a right shift. similarly it is the same trivial to multiply and divide by any power of 2. int a = 123; // or in binary format: a = 0b01111011; assert (a * 2) == (a << 1); // 2 = 2^1, (a << 1) = 11110110 assert (a / 2) == (a >> 1