Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions bit_manipulation/binary_count_trailing_zeros.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def binary_count_trailing_zeros(a: int) -> int:
>>> binary_count_trailing_zeros(4294967296)
32
>>> binary_count_trailing_zeros(0)
0
Traceback (most recent call last):
...
ValueError: Input value must be a positive integer
>>> binary_count_trailing_zeros(-10)
Traceback (most recent call last):
...
Expand All @@ -31,11 +33,11 @@ def binary_count_trailing_zeros(a: int) -> int:
...
TypeError: '<' not supported between instances of 'str' and 'int'
"""
if a < 0:
if a <= 0:
raise ValueError("Input value must be a positive integer")
elif isinstance(a, float):
raise TypeError("Input value must be a 'int' type")
return 0 if (a == 0) else int(log2(a & -a))
return int(log2(a & -a))


if __name__ == "__main__":
Expand Down
Loading