title: Comparing the Most Significant Bit of two numbers: ==, <, <=
body: <p>Is there a quick bit operation to implement <code>msb_equal</code>: a function to check if two numbers have the same most significant bit? </p>
  
  <p>For example, <code>0b000100</code> and <code>0b000111</code> both have 4 as their most significant bit value, so they are most <code>msb_equal</code>. In contrast <code>0b001111</code> has 8 as the MSB value, and <code>0b010000</code> has 16 as it's MSB value, so the pair are <em>not</em> <code>msb_equal</code>.</p>
  
  <p>Similarly, are there fast ways to compute &lt;, and &lt;=?</p>
  
  <p>Examples:</p>
  
  <pre><code>msb_equal(0, 0) =&gt; true
  msb_equal(2, 3) =&gt; true
  
  msb_equal(0, 1) =&gt; false
  msb_equal(1, 2) =&gt; false
  msb_equal(3, 4) =&gt; false
  
  msb_equal(128, 255) =&gt; true
  </code></pre>
  
  <hr>
  
  <p>A comment asks why 0 and 1 are not msb_equal. My view on this is that if I write out two numbers in binary, they are msb_equal when the most significant 1 bit in each is the same bit.</p>
  
  <p>Writing out 2 &amp; 3:</p>
  
  <pre><code>2 == b0010
  3 == b0011
  </code></pre>
  
  <p>In this case, the top most 1 is the same in each number</p>
  
  <p>Writing out 1 &amp; 0:</p>
  
  <pre><code>1 == b0001
  0 == b0000
  </code></pre>
  
  <p>Here, the top most 1s are not the same.</p>
  
  <p>It could be said that as 0 has no top most set bit, <code>msb_equal(0,0)</code> is ambiguous. I'm defining it as <code>true</code>: I feel this is helpful and consistent.</p>