Skip to content

Instantly share code, notes, and snippets.

@rudrankriyam
Last active January 20, 2020 06:51
Show Gist options
  • Select an option

  • Save rudrankriyam/64df0fad178ea36362ae81b9a8d32f4f to your computer and use it in GitHub Desktop.

Select an option

Save rudrankriyam/64df0fad178ea36362ae81b9a8d32f4f to your computer and use it in GitHub Desktop.
Example of using Bitwise AND and XOR operator
func hammingDistance(_ x: Int, _ y: Int) -> Int {
var hammingDistance = x ^ y
var counter = 0
while hammingDistance > 0 {
hammingDistance &= (hammingDistance - 1)
counter += 1
}
return counter
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment