Skip to content

Commit

Permalink
write function to clear ith bit in python
Browse files Browse the repository at this point in the history
  • Loading branch information
justanindieguy committed Jan 24, 2023
1 parent ee9d50a commit e4cb140
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Bit-manipulationTechniques/ClearIthBit/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def clear_ith_bit(n: int, i: int):
mask = ~(1 << i)
return n & mask


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

n = clear_ith_bit(n, i)
print(f"New n value: {n}")


if __name__ == "__main__":
main()

0 comments on commit e4cb140

Please sign in to comment.