Is multiplication and division using shift operators in C actually faster?

Multiplication and division can be achieved using bit operators, for example i*2 = i<<1 i*3 = (i<<1) + i; i*10 = (i<<3) + (i<<1) and so on. Is it actually faster to use say (i<<3)+(i<<1) to multiply with 10 than using i*10 directly? Is there any sort of input that can’t be multiplied or divided … Read more

Extracting bits with a single multiplication

I saw an interesting technique used in an answer to another question, and would like to understand it a little better. We’re given an unsigned 64-bit integer, and we are interested in the following bits: 1…….2…….3…….4…….5…….6…….7…….8……. Specifically, we’d like to move them to the top eight positions, like so: 12345678……………………………………………….. We don’t care about the … Read more