title: Invert enum flags
body: <p>Lets say I have the following flags:</p>
  
  <pre><code>[Flags]
  public enum Foo
  {
      None = 0,
      Foo1 = 1,
      Foo2 = 2,
      Foo4 = 4,
      Foo8 = 8
  }
  </code></pre>
  
  <p>Now I have a variable foo:</p>
  
  <pre><code>var foo = Foo.Foo1 | Foo.Foo4;
  </code></pre>
  
  <p>What I want to get is the following the inverted flags of <code>foo</code>.
  That would mean something like this:</p>
  
  <pre><code>Foo.Foo2 | Foo.Foo8
  </code></pre>
  
  <p>I've tried the ~ operator. But since my enum is a int32 value it inverts all 32 bits. But I actually just would need to invert the bits used by my <code>Foo enum</code>.</p>
  
  <p>EDIT:
  Foo1 | Foo4 would equal the following bitmask:</p>
  
  <pre><code>00000000 00000000 00000000 00000101
  </code></pre>
  
  <p>If you invert that bitmask by using the ~ operator you will get the following result:</p>
  
  <pre><code>11111111 11111111 11111111 11111010
  </code></pre>
  
  <p>The result I would like to have would be:</p>
  
  <pre><code>00000000 00000000 00000000 00001010
  </code></pre>
  
  <p>As you can see. I just would like to invert the bits USED by the Foo enumeration. Not all bits of the whole 32-integer value.</p>