bit_manipulation.index_of_rightmost_set_bit¶
Functions¶
Take in a positive integer 'number'. |
Module Contents¶
- bit_manipulation.index_of_rightmost_set_bit.get_index_of_rightmost_set_bit(number: int) int ¶
Take in a positive integer ‘number’. Returns the zero-based index of first set bit in that ‘number’ from right. Returns -1, If no set bit found.
>>> get_index_of_rightmost_set_bit(0) -1 >>> get_index_of_rightmost_set_bit(5) 0 >>> get_index_of_rightmost_set_bit(36) 2 >>> get_index_of_rightmost_set_bit(8) 3 >>> get_index_of_rightmost_set_bit(-18) Traceback (most recent call last): ... ValueError: Input must be a non-negative integer >>> get_index_of_rightmost_set_bit('test') Traceback (most recent call last): ... ValueError: Input must be a non-negative integer >>> get_index_of_rightmost_set_bit(1.25) Traceback (most recent call last): ... ValueError: Input must be a non-negative integer