MCPcopy
hub / github.com/jwasham/practice-python / hamming_weight

Function hamming_weight

bit_manipulation/bits.py:12–21  ·  view source on GitHub ↗
(x)

Source from the content-addressed store, hash-verified

10
11# Wegner method
12def hamming_weight(x):
13 if x < 0:
14 return None
15
16 count = 0
17 while x:
18 x &= x - 1
19 count += 1
20
21 return count
22
23
24def pop_count(i):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected