code: public static int d(int x, int y) {
          int dist = 0;
          int val = x ^ y;
  
          // Count the number of set bits (Knuth's algorithm)
          while (val != 0) {
              ++dist;
              val &= val - 1;
          }
  
          return dist;
      }
docs: Returns Hamming distance between the two integers.