title: Flags enum & bitwise operations vs. “string of bits”
body: <p>A fellow developer suggested we store a selection of days of the week as 7-character string of 1’s and 0’s, i.e. “1000100” for Monday and Friday. I preferred (and strongly suggested) a solution with a Flags enum and bitwise operations, I think it's a cleaner way of doing this, and it should be easier to understand for other developers.</p>
  
  <pre><code>  [Flags()]
    public enum Weekdays : int
    {
      Monday = 1,
      Tuesday = 2,
      Wednesday = 4,
      Thursday = 8,
      Friday = 16,
      Saturday = 32,
      Sunday = 64
    }
  </code></pre>
  
  <p>However, as I started to implement a sample solution, I realized that maybe the simple string approach was easier after all: Certainly the bit-string is more obvious than “17” if you’re just looking at the data. And I find the C# bitwise operations counter-intuitive and extremely verbose:</p>
  
  <pre><code>Weekdays workDays = Weekdays.Monday | Weekdays.Tuesday;
  if ((workDays &amp; Weekdays.Monday) == Weekdays.Monday) 
  {...}
  </code></pre>
  
  <p>Of course this could be wrapped nicely into extension methods, but then we suddenly end up with at least the same number of lines of code as with the string-solution, and I can hardly argue the bitwise code is easier to read.</p>
  
  <p>That being said, I still would go with a flags enum and bitwise operations. The key benefits I can think of are </p>
  
  <ul>
  <li>Better performance</li>
  <li>Less space needed for storage</li>
  </ul>
  
  <p>So how do I sell the bitwise solution to my colleagues? Should I? What are the other benefits of using this method over strings? After completing the sample project, I found that the team still opted for the string-based solution. I need some better/stronger arguments.
  Why should you use Flags enums rather than simple bit-strings?</p>