Skip to content

Commit 111012b

Browse files
committed
Implemented clear_least_significant_set_bit in single_bit_manipulation_operations.py
1 parent a71618f commit 111012b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

bit_manipulation/single_bit_manipulation_operations.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ def get_bit(number: int, position: int) -> int:
9393
"""
9494
return int((number & (1 << position)) != 0)
9595

96+
def clear_least_significant_set_bit(number: int) -> int:
97+
"""
98+
Clear the least significant set bit.
99+
100+
Details: perform bitwise and for given number and X.
101+
Where X is a number with all the bits - ones and bit on given
102+
position - zero.
103+
104+
>>> clear_least_significant_set_bit(0b1101) # 0b1100
105+
12
106+
>>> clear_least_significant_set_bit(0b1111) # 0b1110
107+
14
108+
"""
109+
return number & (number - 1)
96110

97111
if __name__ == "__main__":
98112
import doctest

0 commit comments

Comments
 (0)