title: Calculate the parity of a byte in Ruby
body: <p>What's the best way to calculate if a byte has odd or even parity in Ruby? I've got a version working: </p>
  
  <pre><code>result = "AB".to_i(16).to_s(2).count('1').odd?
  =&gt; true
  </code></pre>
  
  <p>Converting a number to a string and counting the "1"s seems a poor way of calculating parity though. Any better methods?</p>
  
  <p>I want to be able to calculate the parity of a 3DES key. Eventually, I'll want to convert even bytes to odd.  </p>
  
  <p>Thanks,
  Dan</p>