title: MySQL bitwise operations
body: <p>I am trying to understand bitwise operators in MySQL.</p>
  
  <p>I have:</p>
  
  <pre><code>SELECT 1 &amp; 51 FROM bits = 1
  SELECT 2 &amp; 51 FROM bits = 2
  SELECT 3 &amp; 51 FROM bits = 3
  SELECT 4 &amp; 51 FROM bits = 0
  SELECT 5 &amp; 51 FROM bits = 1
  SELECT 6 &amp; 51 FROM bits = 2
  </code></pre>
  
  <p>With <code>SELECT 1 &amp; 51 FROM bits</code> is this asking that the first bit (1) is present in both 1 and 51, if it is then I understand this.</p>
  
  <p>But <code>SELECT 6 &amp; 51 FROM bits = 2</code> doesn't make sense to me as the 6th bit would be 32(?) which isn't is 6, as 6 is made from the 2nd and 4th bit(?), but 32 is present in 51.</p>
  
  <p>So I am a bit confused as to how this works, could someone please explain?</p>