Skip to content

Commit

Permalink
write function to clear last i bits in python
Browse files Browse the repository at this point in the history
  • Loading branch information
justanindieguy committed Jan 27, 2023
1 parent 150321d commit 066c788
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Bit-manipulationTechniques/ClearLastIBits/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def clear_last_i_bits(n: int, i: int):
mask = -1 << i
return n & mask


def main():
n = 15
i = int(input())

n = clear_last_i_bits(n, i)
print(n)


if __name__ == "__main__":
main()

0 comments on commit 066c788

Please sign in to comment.