intTools: Tools for working with integer values¶
-
fontTools.misc.intTools.
popCount
(v)[source]¶ Return number of 1 bits (population count) of an integer.
If the integer is negative, the number of 1 bits in the twos-complement representation of the integer is returned. i.e.
popCount(-30) == 28
because -30 is:1111 1111 1111 1111 1111 1111 1110 0010
Uses the algorithm from HAKMEM item 169.
- Parameters
v (int) – Value to count.
- Returns
Number of 1 bits in the binary representation of
v
.