title: Fastest Way to XOR all bits from value based on bitmask?
body: <p>I've got an interesting problem that has me looking for a more efficient way of doing things.</p>
  
  <p>Let's say we have a value (in binary)</p>
  
  <pre><code>(VALUE) 10110001
  (MASK)  00110010
  ----------------
  (AND)   00110000
  </code></pre>
  
  <p>Now, I need to be able to XOR any bits from the <code>(AND)</code> value that are set in the <code>(MASK)</code> value (always lowest to highest bit):</p>
  
  <pre><code>(RESULT) AND<sub>1</sub>(0) xor AND<sub>4</sub>(1) xor AND<sub>5</sub>(1) = 0</code></pre>
  
  <p>Now, on paper, this is certainly quick since I can see which bits are set in the mask. It seems to me that programmatically I would need to keep right shifting the MASK until I found a set bit, XOR it with a separate value, and loop until the entire byte is complete.</p>
  
  <p>Can anyone think of a faster way? I'm looking for the way to do this with the least number of operations and stored values.</p>