cours_progra/bac1/q2/fonctio/tp1/algo_q21.py
Debucquoy 4fd7542f03
.
2023-09-20 15:18:20 +02:00

30 lines
492 B
Python

#!/bin/python
def toBinaryString(user_i:int):
squares = [2**i for i in range(32)]
squares.reverse()
ret = ''
show = False
for s in squares:
if user_i & s:
ret += '1'
show=True
else:
if show:
ret += '0'
return ret
def main():
"""
Ask the user for an input
"""
user_in = input("entrez un nombre :")
print(toBinaryString(int(user_in)))
if __name__ == "__main__":
main()