Created
May 28, 2021 13:58
-
-
Save rphuber/596905c452215f771dbf5784f3d1256b 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
func CountBits(x int) int { | |
numBits := 0 | |
for x != 0 { | |
numBits += x & 1 | |
x >>= 1 | |
} | |
return numBits | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment