add a script that converts binary mantices into normal decimal numbers
This commit is contained in:
parent
49dbc9a164
commit
0df9dd3016
|
@ -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}")
|
Loading…
Reference in New Issue