solution.c 265 B

1234567891011121314151617181920
  1. int countOnesBits(int x) {
  2. int result = 0;
  3. while (x > 0) {
  4. if (x % 2 == 1) {
  5. result++;
  6. }
  7. x = x >> 1;
  8. }
  9. return result;
  10. }
  11. int hammingDistance(int x, int y) {
  12. return countOnesBits(x ^ y);
  13. }