MCPcopy Create free account
hub / github.com/CheckPointSW/Karta / countSetBits

Function countSetBits

src/config/utils.py:332–345  ·  view source on GitHub ↗

Count the set ('1') bits in the given numeric constant. Args: const (int): numeric constant to rank Return Value: Number of set ('1') bits

(const)

Source from the content-addressed store, hash-verified

330###################
331
332def countSetBits(const):
333 """Count the set ('1') bits in the given numeric constant.
334
335 Args:
336 const (int): numeric constant to rank
337
338 Return Value:
339 Number of set ('1') bits
340 """
341 # we only work on unsigned values
342 if const < 0:
343 const += 2 ** NUM_BITS_IN_CONST
344 # simply count them
345 return bin(const).count("1")
346
347def measureBitsVariance(const):
348 """Measures the bits "entropy", i.e. the variance of the bit flips.

Callers 1

rankConstFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected