bit_manipulation.count_1s_brian_kernighan_method ================================================ .. py:module:: bit_manipulation.count_1s_brian_kernighan_method Functions --------- .. autoapisummary:: bit_manipulation.count_1s_brian_kernighan_method.get_1s_count Module Contents --------------- .. py:function:: get_1s_count(number: int) -> int Count the number of set bits in a 32 bit integer using Brian Kernighan's way. Ref - https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan >>> get_1s_count(25) 3 >>> get_1s_count(37) 3 >>> get_1s_count(21) 3 >>> get_1s_count(58) 4 >>> get_1s_count(0) 0 >>> get_1s_count(256) 1 >>> get_1s_count(-1) Traceback (most recent call last): ... ValueError: Input must be a non-negative integer >>> get_1s_count(0.8) Traceback (most recent call last): ... ValueError: Input must be a non-negative integer >>> get_1s_count("25") Traceback (most recent call last): ... ValueError: Input must be a non-negative integer