Created
August 18, 2023 15:31
-
-
Save dimitrilw/4076901c21a906376d507341a025cef9 to your computer and use it in GitHub Desktop.
Go (golang) int to bitcount
This file contains 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 bitCount(n int) (res int) { | |
for n > 0 { | |
if n & 1 == 1 { res++ } | |
n >>= 1 | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment