title: Bit set/clear in C?
body: <p>How do I write to a single bit? I have a variable that is either a 1 or 0 and I want to write its value to a single bit in a 8-bit <code>reg</code> variable.</p>
  
  <p>I know this will set a bit:</p>
  
  <pre><code>reg |= mask; // mask is (1 &lt;&lt; pin)
  </code></pre>
  
  <p>And this will clear a bit:</p>
  
  <pre><code>reg &amp;= ~mask; // mask is (1 &lt;&lt; pin)
  </code></pre>
  
  <p>Is there a way for me to do this in one line of code, without having to determine if the value is high or low as the input?</p>