Created
July 31, 2009 12:14
-
-
Save embed/159199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned hamdist(unsigned x, unsigned y) | |
{ | |
unsigned dist = 0, val = x ^ y; | |
// Count the number of set bits (Knuth's algorithm) | |
while(val) | |
{ | |
++dist; | |
val &= val - 1; | |
} | |
return dist; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment