I'm reading Alex's tutorial on Bitwise operation on this website.
I'm a bit confused (no pun intended) with this following description which seems incorrect:
***
The leftshift operator is the equivalent of moving all the bits of a number a specified number of places to the left:[variable]<<[number of places]
For instance, consider the number 8 written in binary 00001000. If we wanted to shift it to the left 2 places, we'd end up with 00100000; everything is moved to the left two places, and zeros are added as padding. This is the number 32 -- in fact, left shifting is the equivalent of multiplying by a power of two.
Code:
int mult_by_pow_2(int number, int power)
{
return number<<power;
}
***
Specifically the line in red.
It appears to me this is incorrect; that the leftshift operator is the equivalent of multiplying by two (not by the power of two).
So 8<<1 is 8*2 or 16. 8<<2 is 8*2*2 or 32. Where as 8^2 (8 to the power of 2) is actually 64.
Am I somehow mis-interpreting this?
Thanks