Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Created June 23, 2020 14:18
Show Gist options
  • Save ashkrit/258ba868145b39743d3b5a5badcfbbfa to your computer and use it in GitHub Desktop.
Save ashkrit/258ba868145b39743d3b5a5badcfbbfa to your computer and use it in GitHub Desktop.
/*
Using bits count to find distance between 2 integer. Some of application are error deduction while data transfer
*/
public class HammingDistance {
public static int weight(int value) {
return Bits.countBits(value);
}
public static int distance(int value1, int value2) {
return Bits.countBits(value1 ^ value2);
}
public static int distance(String value1, String value2) {
throw new IllegalArgumentException("Not implemented");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment