title: C++: How to get the MSB (Most-Significant Bit) of a Bitset (using bitwise operators)?
body: <p>I am trying to convert a decimal number to a bitset of length <code>27</code> and then retrieve the MSB (left-most bit) from that bitset using bitwise operators. For example, the number <code>67108865</code> is expressed as <code>100000000000000000000000001</code> and the MSB is <code>1</code>. Another example is the number <code>1</code> which is expressed as <code>000000000000000000000000001</code> and the MSB is <code>0</code>.</p>
  
  <p>Below is my C++ code:</p>
  
  <pre><code>unsigned int value = 67108865;
  bitset&lt;27&gt; bs(value);
  int most_significant_bit = bs &gt;&gt; (sizeof(value)*8 - 1) &amp; 1;
  cout &lt;&lt; most_significant_bit &lt;&lt; endl;
  </code></pre>
  
  <p>However, I receive the following error:</p>
  
  <blockquote>
    <p>error: no match for ‘operator&amp;’ (operand types are ‘std::bitset&lt;27>’
    and ‘int’)    int most_significant_bit = bs >> (sizeof(value)*8 - 1) &amp;
    1;</p>
  </blockquote>
  
  <p>How would I retrieve the MSB using bitwise operators?</p>