Using only adding, subtracting, and enumerating bits, how can I multiply an integer by a given number?
For example, I want to multiply an integer by 17.
I know that the left offset is multiplied by a multiple of 2, and the right offset divides by 2, but I don't know how to generalize it.
What about negative numbers? Convert to two additions and perform the same procedure?
( EDIT: Well, I got this, it doesnโt matter. You convert into two additions, and then go according to the number from left to right, and not from right to left.)
Now the tricky part appears. We can use only 3 operators.
For example, multiplying by 60, I can execute using this:
(x << 5) + (x << 4) + (x << 3) + (x << 2)
Where x is the number I multiply. But these are 7 operators - how can I condense this to use only 3?
source share