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;
    }
public static int d ( int x , int y ) { int dist = 0 ; int val = x ^ y ; while ( val != 0 ) { ++ dist ; val &= val - 1 ; } return dist ; }
Returns Hamming distance between the two integers.