title: Bitshift to multiply by any number
body: <p>Using only adding, subtracting, and bitshifting, how can I multiply an integer by a given number?</p>
  
  <p>For example, I want to multiply an integer by 17.</p>
  
  <p>I know that shifting left is multiplying by a multiple of 2 and shifting right is dividing by a power of 2 but I don’t know how to generalize that.</p>
  
  <hr>
  
  <p>What about negative numbers? Convert to two's complement and do the same procedure?</p>
  
  <p>(<strong>EDIT:</strong> OK, I got this, nevermind. You convert to two's complement and then do you shifting according to the number from left to right instead of right to left.)</p>
  
  <hr>
  
  <p><strong>Now the tricky part comes in. We can only use 3 operators.</strong> </p>
  
  <p>For example, multiplying by 60 I can accomplish by using this:</p>
  
  <pre><code>(x &lt;&lt; 5) + (x &lt;&lt; 4) + (x &lt;&lt; 3) + (x &lt;&lt; 2)
  </code></pre>
  
  <p>Where <code>x</code> is the number I am multiplying. But that is 7 operators - how can I condense this to use only 3?</p>