From 0df9dd30161c1e4ff0d35417977a01d2f730043b Mon Sep 17 00:00:00 2001 From: dymik739 Date: Fri, 12 May 2023 19:39:02 +0300 Subject: [PATCH] add a script that converts binary mantices into normal decimal numbers --- src/binary-to-decimal-mantice-converter.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/binary-to-decimal-mantice-converter.py diff --git a/src/binary-to-decimal-mantice-converter.py b/src/binary-to-decimal-mantice-converter.py new file mode 100644 index 0000000..fcb13c1 --- /dev/null +++ b/src/binary-to-decimal-mantice-converter.py @@ -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}")