5
« on: September 09, 2007 »
Now, I found a way, I think it's pretty simple, but I'd like to share my incredibly deep insights into maths with you.
Excuse the shitty code, but it's late.
(in FreeBasic written)
cconv(q as double,s as uinteger) 'q = Number you'd like to convert
's = System to which you'd like to convert
dim as integer d,c
dim as double q
dim as string o,u,r(36)
declare function modulo(byval x as double,byval y as double) as double
for c=0 to 9
r(c)=str(c)
next
for c=asc("a") to asc("z")
r(c-asc("a")+10)=chr(c)
next
d=int(q)
q-=d
while modulo(q,1)<>0
q*=s
wend
while q<>0 or d<>0
if q<>0 then
p=modulo(q,s)
o=r(p)+o
q=int(q/s)
elseif d<>0 then
q=modulo(d,s)
u=r(p)+u
d=int(d/s)
end if
wend
print u+"."+o
function modulo(byval x as double,byval y as double) as double
return x-y*int(x/y)
end function
sleep
the code needs improvement, so if you find time, please have a look at it and improve it, I don't know how, but it could be that it makes mistakes at some points, I'll have a look at it as soon as I find time too do so.