title: Comparing a bit to a boolean
body: <p>Say I have a set of flags, encoded in a uint16_t <code>flags</code>. For example, <code>AMAZING_FLAG = 0x02</code>.
  Now, I have a function. This function needs to check if I want to change the flag, because if I want to do that, I need to write to flash. And that is expensive. Therefore, I want a check which tells me if <code>flags &amp; AMAZING_FLAG</code> is equal to <code>doSet</code>. This is the first idea:</p>
  
  <pre><code>setAmazingFlag(bool doSet)
  {
      if ((flags &amp; AMAZING_FLAG) != (doSet ? AMAZING_FLAG : 0)) {
          // Really expensive thing
          // Update flags
      }
  }
  </code></pre>
  
  <p>This is not an intuitive if statement.
  I feel like there should be a better way, something like:</p>
  
  <pre><code>if ((flags &amp; AMAZING_FLAG) != doSet){
  
  }
  </code></pre>
  
  <p>But this does not actually work, <code>true</code> seems to be equal to <code>0x01</code>.</p>
  
  <p>So, is there a neat way to compare a bit to a boolean?</p>