title: Finding if a value falls within a range, using bitwise operators in C
body: <p>So i am working on this method, but am restricted to using ONLY these operators:</p>
  
  <p>&lt;&lt;, >>, !, ~, &amp;, ^, |, + </p>
  
  <p>I need to find if a given int parameter can be represented using 2's complement arithmetic in a given amount of bits.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>int validRange(int val, int bits){
      int minInRange = ~(1&lt;&lt;(bits + ~0 ))+1;   //the smallest 2's comp value possible with this many bits
      int maxInRange = (1&lt;&lt;(bits+~0))+~0;  //largest 2's comp value possible 
      ..........
  }
  </code></pre>
  
  <p>This is what I have so far, and all I need to do now is figure out how to tell if minInRange &lt;= val &lt;=maxInRange. I wish I could use the greater than or less than operator, but we are not allowed. What is the bitwise way to check this?</p>
  
  <p>Thanks for any help!</p>