summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-04-28 18:00:14 +0200
committerSanto Cariotti <sancn@live.com>2017-04-28 18:00:14 +0200
commitcb4611b43d40bb2a89646f3d797f4a05ba51683d (patch)
tree499b64eb5e5e5f384ca4e1879fe6ce57c0d509c0 /python
parent52de06bfdb6499e3cc166fd4a9e54aa953f2fe12 (diff)
Added conversion bin-dec in Python
Diffstat (limited to 'python')
-rw-r--r--python/conversioneBinariaDec.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/python/conversioneBinariaDec.py b/python/conversioneBinariaDec.py
new file mode 100644
index 0000000..cf1087b
--- /dev/null
+++ b/python/conversioneBinariaDec.py
@@ -0,0 +1,30 @@
+from math import pow
+
+b = 32
+v = []
+
+for i in range(b):
+ v.append(0)
+
+str = raw_input('Stringa: ')
+
+if len(str) < b:
+ valVuoto = len(str)
+
+i = b - valVuoto
+j = 0
+
+while i < b:
+ v[i] = int(str[j])
+ i += 1
+ j += 1
+
+i = b - 1
+j = num = 0
+
+while i > -1:
+ num += v[i] * pow(2, j)
+ i -= 1
+ j += 1
+
+print(int(num)) \ No newline at end of file