Skip to content

Instantly share code, notes, and snippets.

@dimitrilw
Created August 18, 2023 15:31
Show Gist options
  • Save dimitrilw/4076901c21a906376d507341a025cef9 to your computer and use it in GitHub Desktop.
Save dimitrilw/4076901c21a906376d507341a025cef9 to your computer and use it in GitHub Desktop.
Go (golang) int to bitcount
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