MCPcopy 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

1package number_of_1_bits_191
2
3func 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_hammingWeightFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_hammingWeightFunction · 0.68