title: Double comparison trick in Java
body: <p>C++ allows you to combine two integer comparisons in one for range checking, like</p>
  
  <pre><code>(unsigned)X &lt; (unsigned)Upper
  </code></pre>
  
  <p>which returns true when</p>
  
  <pre><code>0 &lt;= X &lt; Upper
  </code></pre>
  
  <p>The Java language has no unsigned type. Do you see a way to obtain the same effect, using a single comparison and not too much overhead ?</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>From a comment by @Bathsheba, the char type is unsigned 16 bits and will be fit for my purpose, as my integers are actually in the range of shorts.</p>
  
  <p>The question remains open for plain <code>int</code>s.</p>
  
  <p>Possibly something in the line of <code>(X | (Upper - 1 - X)) &gt;= 0</code>, which allows a range of 30 bits.</p>