title: Bitwise operations and shifts
body: <p>Im having some trouble understanding how and why this code works the way it does. My partner in this assignment finished this part and I cant get ahold of him to find out how and why this works. I've tried a few different things to understand it, but any help would be much appreciated. This code is using 2's complement and a 32-bit representation.</p>
  
  <pre><code>/* 
   * fitsBits - return 1 if x can be represented as an 
   *  n-bit, two's complement integer.
   *   1 &lt;= n &lt;= 32
   *   Examples: fitsBits(5,3) = 0, fitsBits(-4,3) = 1
   *   Legal ops: ! ~ &amp; ^ | + &lt;&lt; &gt;&gt;
   *   Max ops: 15
   *   Rating: 2
   */
  int fitsBits(int x, int n) {
      int r, c;
      c = 33 + ~n;
      r = !(((x &lt;&lt; c)&gt;&gt;c)^x);
      return r;
  }
  </code></pre>