cours_progra/bac1/q2/fonctio/tp1/algo_q21.py

30 lines
492 B
Python
Raw Normal View History

2023-04-26 11:24:13 +02:00
#!/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()