.
This commit is contained in:
29
bac1/q2/fonctio/tp1/algo_q21.py
Normal file
29
bac1/q2/fonctio/tp1/algo_q21.py
Normal file
@ -0,0 +1,29 @@
|
||||
#!/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()
|
Reference in New Issue
Block a user