Simple question, but I can't quite seem to figure it out:
If i have an integer, say 12, and I perform the following bit-manipulation on it:
int i = 12;
i = (i << 3) + (i << 1);
I end up with 120 (12*10). This is the case with any number.
Can someone explain to me, succinctly, why it is that this works? (I'm obviously missing something quite rudimentary when it comes to bitshifting).
Express as multiplication.
i = (i << 3) + (i << 1);
i = (i * 8) + (i * 2);
i = 8i + 2i
i = 10i
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With