title: Bit setting and code readability
body: <p>I have an Arduino application (well actually a library) that has a number of status flags in it - and originally I simply declared them as ints (well uint8_t so 8 bit unsigned chars in this case). But I could have combined them all into one integer and used bitmask operations to set and test the status.</p>
  
  <p>An example of the former:</p>
  
  <pre><code>if (_shift == HIGH)
  {
      _shift = LOW;
  }
  else
  {
      _shift = HIGH;
  }
  </code></pre>
  
  <p>an example of the latter</p>
  
  <pre><code>#define SHIFT_BIT 0
  
  if (bitRead(_flags, SHIFT_BIT) == HIGH)
  {
     bitWrite(_flags, SHIFT_BIT, LOW);
  }
  else
  {
     bitWrite(_flags, SHIFT_BIT, HIGH);
  }
  </code></pre>
  
  <p>The former reads better, but the latter is more efficient (space and time). Should the space and time efficiency always win in this situation or is this a kind of optimization that should only happen when needed?</p>
  
  <p>(Added)</p>
  
  <p>For completeness here's the Wiring definition of those bitWrite etc. macros:</p>
  
  <pre><code>#define bitRead(value, bit) (((value) &gt;&gt; (bit)) &amp; 0x01)
  #define bitSet(value, bit) ((value) |= (1UL &lt;&lt; (bit)))
  #define bitClear(value, bit) ((value) &amp;= ~(1UL &lt;&lt; (bit)))
  #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
  </code></pre>