title: Bit flags from boolean variables in Java and MySQL
body: <p>I just want to create a bit flag from a series of boolean variables so I can store one variable in a MySQL database instead of several booleans. For example, I have three boolean flags (A, B, C) and want to create a single bit flag based on the values of the boolean flags. I think this would work but I'm guessing there's a better (or more legible) way to do this:</p>
  
  <pre><code>int myBitFlag = A ? 1:0;
  myBitFlag += B ? 2:0;
  myBitFlag += C ? 4:0;
  </code></pre>
  
  <p>I'm not sure why I can't find anything about this and maybe it's because I'm doing it wrong or not using the correct terminology..</p>
  
  <p>And to select all of the entries with B=true, would I use this?</p>
  
  <pre><code>SELECT * FROM table WHERE myBitFlag &amp; 2 = 1
  </code></pre>