123456789101112131415161718192021 |
- #include <stdio.h>
-
- int countBits(int);
-
- int hammingDistance(int x, int y) {
- return countBits(x ^ y);
- }
-
- int countBits(int v) {
- int c;
- for (c = 0; v; v >>= 1) {
- c += v & 1;
- }
- return c;
- }
-
- int main() {
- printf("Expected: 2\n");
- printf("Got: %d\n", hammingDistance(1, 4));
- return 0;
- }
|