add a script that converts binary mantices into normal decimal numbers

This commit is contained in:
dymik739 2023-05-12 19:39:02 +03:00
parent 49dbc9a164
commit 0df9dd3016
1 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,14 @@
def convert(x):
result = 0
for p, i in enumerate(x):
if i == '1':
result += 2**(-p-1)
return result
# sample implementation
if __name__ == "__main__":
x = input("Enter mantice: ")
r = convert(x)
print(f"Result: {r}")