(x << 4)
is essentially x * 16
, (x << 2)
is x * 4
, and (x << 1)
is x * 2
. Therefore, 16x - 4x - 2x = 10x
.
As for why (x << 4)
is equal to x * 16
, it's because of the binary representation. Let's take 10 in binary (only 8 bits shown for clarity; there's actually a bunch more zeroes to the left):
00001010
Now let's shift left 4 spaces:
10100000
That's 160.
A way of thinking of this is that when you add a zero in base ten (i.e. 10 -> 100), you're multiplying by 10. When you add a zero in base two, you're multiplying by 2. Therefore, shifting 4 spaces (and therefore adding 4 zeroes) multiplies by 2*2*2*2
= 16
.