forked from codezoned/ScriptsDump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseconversion from base 2 to 32.py
145 lines (129 loc) · 3.38 KB
/
baseconversion from base 2 to 32.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import datetime
print("Today's Date and time is :", end=" ")
print(str(datetime.datetime.now()))
print("")
print("------This program converts number with any base to the base entered by the User with guaranteed accuracy of minimum 3 decimal places.------")
print(" Note: base should be less than or equal to 32 and greater than equal to 2 ")
print("")
print("**It rounds off the number upto 20th decimal places**")
print("")
tsssy=""
while(tsssy==""):
n=int(input("Enter base for the number"))
print("")
dic={'a':10,'b':11,'c':12,'d':13,'e':14,'f':15,'g':16,'h':17,'i':18,'j':19,'k':20,'l':21,'m':22,'n':23,'o':24,'p':25,'q':26,'r':27,'s':28,'t':29,'u':30,'v':31}
rttu=""
if n>10:
xyzA=12
while(xyzA>0):
asd=[]
akd=[]
m=input("Enter Number with base "+str(n)).lower()
print("")
gg="".join(m)
gg=gg.split(".")
m=gg[0]
xyz=0
tty=0
ks=0
if len(gg)==2:
for kjj in range(len(gg[1])):
if 97<=ord(gg[1][kjj])<=122:
u=gg[1][kjj]
ks=dic[u]
if int(ks)>=n:
xyz=-1
else:
akd.append(str(ks))
else:
akd.append(gg[1][kjj])
for i in range(len(m)):
if 97<=ord(m[i])<=122:
u=m[i]
ks=dic[u]
if int(ks)>=n:
xyz=-1
else:
asd.append(str(ks))
else:
asd.append(m[i])
if xyz==-1:
xyzA=12
print("Enter number again correctly, Make sure digits for the number should be less than the base of the number")
else:
xyzA=-9
if n<=10:
xyzA=12
while(xyzA>0):
asd=[]
akd=[]
m=input("Enter Number with base "+str(n)).lower()
print("")
gg="".join(m)
gg=gg.split(".")
m=gg[0]
xyz=0
ks=0
if len(gg)==2:
for kjj in range(len(gg[1])):
ks=gg[1][kjj]
if int(ks)>=n:
xyz=-1
else:
akd.append(gg[1][kjj])
for i in range(len(m)):
if int(m[i])>=n:
xyz=-1
else:
asd.append(m[i])
if xyz==-1:
xyzA=12
print("Enter number again correctly, Make sure digits for the number should be less than the base of the number")
else:
xyzA=-9
lm=int(input("Enter base to which you want to convert the given number"))
print("")
c=0
d=0
e=-1
f=0
t=1
y=""
if len(gg)==2:
hj=1
uu=1
for ty in range(len(akd)):
f+=int(akd[ty])*(n**e)
e-=1
while(hj<=20):
uu=f*lm
if int(uu)>=10:
for i in range(97,119):
if dic[chr(i)]==int(uu):
rttu+=chr(i)
if int(uu)<10:
rttu+=str(int(uu))
f=uu-int(uu)
hj+=1
for i in range(len(asd)-1,-1,-1):
c+=int(asd[i])*(n**d)
d+=1
while(t>0):
ggg=c%lm
if int(ggg)>=10:
for iu in range(97,119):
if dic[chr(iu)]==int(ggg):
y+=chr(iu)
if int(ggg)<10:
y+=str(c%lm)
c=c//lm
if c==0:
t=-1
print("Number with base "+str(n)+" was "+".".join(gg)+" .Now it is converted into base "+str(lm)+" the required number is:",end=" ")
print(y[::-1],end=".")
if len(rttu)!=0:
print(rttu)
if len(rttu)==0:
print(0)
print("")
uy=input("Press Enter to continue or hit any key to Exit !")