-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinary to decimal 2.0.py
More file actions
72 lines (47 loc) · 1.5 KB
/
Binary to decimal 2.0.py
File metadata and controls
72 lines (47 loc) · 1.5 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
print("Always input the binary value as a float value"," #RAPA")
print(" Eg :- 101.0 ")
print(" 10.1 ")
print(" 10110.0 ")
print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
while 1 :
print()
value = ""
binvalue1 =0
binvalue2 =0
xy="-"
binvalue1,binvalue2 = input("Enter Binary Value : " ).split(".")
print("------------------ ",xy*(len(binvalue1)+len(binvalue2)+1))
print()
for i in binvalue1:
if int(i) > 1 or int(i) < 0 :
value = "notright"
for i in binvalue2:
if int(i) > 1 or int(i) < 0 :
value = "notright"
if value == "notright" :
print("The input value is incorrect - check it again")
else:
decimal= 0
n=2
powert=0
lens = len(binvalue1) - 1
for i in range(lens,-1,-1 ):
decimal += int(binvalue1[i])*(n**powert)
powert += 1
decimal1 = 0
n1=2
powert1 = 1
value2 = ""
for i in binvalue2:
decimal1 += int(i)*1/(n1**powert1)
powert1 += 1
decimal1 = str(decimal1)
print("Decimal Number :",decimal,end=".")
for i in decimal1 :
if i == "." :
value2 = "startp"
if value2 == "startp" :
if i != "." :
print(i,end="")
print()
print("_______________________________________________")