title: The hunt for the fastest Hamming Distance C implementation
body: <p>I want to find how many different characters two strings of equal length have. I have found that xoring algorithms are considered to be the fastest, but they return distance expressed in bits. I want the results expressed in characters. Suppose that "pet" and "pit" have distance 1 expressed in characters but 'e' and 'i' might have two different bits, so xoring returns 2.</p>
  
  <p>The function i wrote is:</p>
  
  <pre><code>// na = length of both strings
  unsigned int HammingDistance(const char* a, unsigned int na, const char* b) {
  
      unsigned int num_mismatches = 0;
      while (na) {
          if (*a != *b)
              ++num_mismatches;
  
          --na;
          ++a;
          ++b;
      }
  
      return num_mismatches;
  }
  </code></pre>
  
  <p>Could it become any faster?
  Maybe using some lower level commands or implementing a different algorithm?</p>
  
  <p><strong>System: Gcc 4.7.2 on Intel Xeon X5650</strong></p>
  
  <p>Thank you</p>