title: Simple boolean operators for bit flags
body: <p>I am attempting to learn more about this to implement in my project.</p>
  
  <p>I currently have got this basically:</p>
  
  <pre><code>unsigned char flags = 0; //8 bits
  
  flags |= 0x2; //apply random flag
  
  if(flags &amp; 0x2) {
     printf("Opt 2 set");
  }
  </code></pre>
  
  <p>Now I am wishing to do a little more complex things, what I am wanting to do is apply three flags like this:</p>
  
  <pre><code>flags = (0x1 | 0x2 | 0x4);
  </code></pre>
  
  <p>And then remove flags <code>0x1</code> and <code>0x2</code> from it? I thought I could do something like this applying bitwise NOT (and bitwise AND to apply it):</p>
  
  <pre><code>flags &amp;= ~(0x1 | 0x2);
  </code></pre>
  
  <p>Apparently they remain there or something either way when I check.</p>
  
  <p>I also do not know how to check if they do NOT exist in the bit flags (so I cannot check if my previous code works), would it be something like this?</p>
  
  <pre><code>if(flags &amp; ~0x2) 
      printf("flag 2 not set");
  </code></pre>
  
  <p>I can not find any resources from my recent searches that apply to this, I am willing to learn this to teach others, I am really interested. I apologize if this is confusing or simple.</p>