Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/austingebauer/go-leetcode
/ hammingWeight
Function
hammingWeight
number_of_1_bits_191/solution.go:3–14 ·
view source on GitHub ↗
(num uint32)
Source
from the content-addressed store, hash-verified
1
package
number_of_1_bits_191
2
3
func
hammingWeight(num uint32) int {
4
ones := 0
5
for
num != 0 {
6
if
num%2 == 1 {
7
ones++
8
}
9
10
num = num / 2
11
}
12
13
return
ones
14
}
Callers
1
Test_hammingWeight
Function · 0.85
Calls
no outgoing calls
Tested by
1
Test_hammingWeight
Function · 0.68