-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin2dec.py
More file actions
46 lines (22 loc) · 758 Bytes
/
bin2dec.py
File metadata and controls
46 lines (22 loc) · 758 Bytes
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
## Made by Ertan Özdemir - COE103 Computational Thinking HW01 | 11.2019 ##
def bin2dec(binary_val):
a = str(binary_val)
a = a[::-1]
binary_list=[]
counter=0
dec_val=0
for i in a:
binary_list.append(i)
lenghtOfValue=len(binary_list)
while lenghtOfValue>=1:
if binary_list[counter]=="1":
lenghtOfValue=lenghtOfValue-1
dec_val=dec_val+(2**(counter))
counter=counter+1
elif binary_list[counter]=="0":
lenghtOfValue=lenghtOfValue-1
counter=counter+1
else:
print("Wrong Number")
break
print(dec_val)