Skip to content

Commit

Permalink
write function to set 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 ea31fa1 commit b39803b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Bit-manipulationTechniques/SetIthBit/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def set_ith_bit(n: int, i: int):
mask = (1 << i)
return (n | mask)


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

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


if __name__ == "__main__":
main()

0 comments on commit b39803b

Please sign in to comment.