summaryrefslogtreecommitdiff
path: root/python/conversioneBinariaDec.py
blob: 113eb850b67ca17bdd8ad8a24f9dcfa4e0d553e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import math

b = 32
v = [0 for i in range(b)]

stringa = input('Stringa: ')

if len(stringa) < b:
    valVuoto = len(stringa)

i = b - valVuoto
j = 0

while i < b:
    v[i] = int(stringa[j])
    i += 1
    j += 1

i = b - 1
j = num = 0

while i > -1:
    num += v[i] * math.pow(2, j)
    i -= 1
    j += 1

print(int(num))