diff --git a/Bit-manipulationTechniques/GetIthBit/main.py b/Bit-manipulationTechniques/GetIthBit/main.py new file mode 100644 index 0000000..3128cca --- /dev/null +++ b/Bit-manipulationTechniques/GetIthBit/main.py @@ -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()