1def binToDec(num):
2
3 temp = str(num)
4 arr = []
5 final = []
6
7 for i in temp:
8 arr.append(i)
9
10 arrNums = [str(x) for x in arr]
11 arrNums.reverse()
12
13 j = 0
14 for i in range(0, len(arrNums)):
15 factor = arrNums[i]*(2**j)
16 j += 1
17 final.append(factor)
18
19 decimal = 0
20 for i in range(0, len(final)):
21 decimal += final[i]
22
23 return decimal
24
25if __name__ == "__main__":
26 num = 101000
27 print(binToDec(num)) # Expected Output : 40