title: bitwise division rounding to nearest zero
body: <p>I want to perform an signed integer bitwise division by a power of 2. However, I encounter several problem. I just wonder if anyone can help me.</p>
  
  <p>First, I try to use bit shifting alone:</p>
  
  <pre><code>int result = number &gt;&gt; n;
  </code></pre>
  
  <p>However, I got a problem when I try to divide a negative number. (it always round with a number with bigger magnitude. example: -9/4=-3 instead of -2. So, I look this problem in the internet, that end me up with this solution:</p>
  
  <pre><code>int result = (number + (1&lt;&lt;n)-1) &gt;&gt; n;
  </code></pre>
  
  <p>However, when I try 11/4 = 3 instead of 2</p>
  
  <p>Any suggestions? I can only use ! ~ &amp; ^ | + &lt;&lt; >> (no loop or if/switch allowed)</p>