title: Bit twiddling for checking whether a number is in particular range
body: <p>I found some interesting bit twiddling in <code>"source\common\unicode\utf.h"</code> file of ICU library (International Components for Unicode). The bit twiddling is intended for checking whether a number is in a particular range.</p>
  
  <pre><code>// Is a code point in a range of U+d800..U+dbff?
  #define U_IS_LEAD(c) (((c)&amp;0xfffffc00)==0xd800)
  </code></pre>
  
  <p>I have figured out the magic number (0xfffffc00) come from:</p>
  
  <pre><code>MagicNumber = 0xffffffff - (HighBound - LowBound)
  </code></pre>
  
  <p>However, I also found that the formula doesn't apply to every arbitrary range. Does somebody here know in what circumstance the formula works?</p>
  
  <p>Is there another bit twiddling for checking whether a number is in particular range?</p>