title: counting the number of bit required to represent an integer in 2's complement
body: <p>I have to write a function that count the number of bit required to represent an int in 2's complement form. The requirement:</p>
  
  <pre><code>1. can only use: ! ~ &amp; ^ | + &lt;&lt; &gt;&gt;
  2. no loops and conditional statement
  3. at most, 90 operators are used
  </code></pre>
  
  <p>currently, I am thinking something like this:</p>
  
  <pre><code>int howManyBits(int x) {
     int mostdigit1 = !!(0x80000000 &amp; x);
     int mostdigit2 = mostdigit1 | !!(0x40000000 &amp; x);
     int mostdigit3 = mostdigit2 | !!(0x20000000 &amp; x);
     //and so one until it reach the least significant digit
     return mostdigit1+mostdigit2+...+mostdigit32+1;
  }
  </code></pre>
  
  <p>However, this algorithm doesn't work. it also exceed the 90 operators limit. any suggestion, how can I fix and improve this algorithm? </p>