Last active
November 25, 2021 00:48
-
-
Save mizhi/acecabd05e34420d8404f4d99118bc1a to your computer and use it in GitHub Desktop.
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
| # From a daily programming challenge on the Operation Code slack | |
| def hamming(x: int, y: int) -> int: | |
| """Compute number of bits where x and y differ. | |
| """ | |
| z = x ^ y | |
| count = 0 | |
| while z > 0: | |
| count += (z & 0x1) | |
| z >>= 1 | |
| return count | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment