title: Why use flags+bitmasks rather than a series of booleans?
body: <p>Given a case where I have an object that may be in one or more true/false states, I've always been a little fuzzy on why programmers frequently use flags+bitmasks instead of just using several boolean values.  </p>
  
  <p>It's all over the .NET framework.  Not sure if this is the best example, but the .NET framework has the following:</p>
  
  <pre><code>public enum AnchorStyles
  {
      None = 0,
      Top = 1,
      Bottom = 2,
      Left = 4,
      Right = 8
  }
  </code></pre>
  
  <p>So given an anchor style, we can use bitmasks to figure out which of the states are selected.  However, it seems like you could accomplish the same thing with an AnchorStyle class/struct with bool properties defined for each possible value, or an array of individual enum values.</p>
  
  <p>Of course the main reason for my question is that I'm wondering if I should follow a similar practice with my own code. </p>
  
  <p>So, why use this approach?</p>
  
  <ul>
  <li>Less memory consumption?  (it doesn't <em>seem</em> like it would consume less than an array/struct of bools)</li>
  <li>Better stack/heap performance than a struct or array?</li>
  <li>Faster compare operations?  Faster value addition/removal?</li>
  <li>More convenient for the developer who wrote it?</li>
  </ul>