Last active
January 20, 2020 06:51
-
-
Save rudrankriyam/64df0fad178ea36362ae81b9a8d32f4f to your computer and use it in GitHub Desktop.
Example of using Bitwise AND and XOR operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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