Skip to content

Commit

Permalink
write function to get 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 db436e0 commit b183515
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Bit-manipulationTechniques/GetIthBit/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def get_ith_bit(n: int, i: int):
mask = 1 << i
return 1 if (n & mask) > 0 else 0


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

print(f"Bit at {i}th position: {get_ith_bit(n, i)}")


if __name__ == "__main__":
main()

0 comments on commit b183515

Please sign in to comment.