recursion version:
sync on : sync 30 : sync
decval=13
base=2
binary$=value2baser(decval,2)
octal$=value2baser(decval,base+6)
hexdec$=value2baser(decval,base+14)
`binary$=value2base(decval,2)
`octal$=value2base(decval,base+6)
`hexdec$=value2base(decval,base+14)
print str$(decval);" -> ";binary$;" (binary)"
print str$(decval);" -> ";octal$;" (octal)"
print str$(decval);" -> ";hexdec$;" (hexadecimal)"
sync
wait key
end
function value2base(v,base)
local b$, t$, rmd, v2
repeat
rmd = v mod base
v2 = v / base
`print v; ", ";v2; ", ";rmd;", base= ";base // debug only
v = v2
if base = 16
if rmd >=10 and rmd<=15
if rmd=10 then t$="A"
if rmd=11 then t$="B"
if rmd=12 then t$="C"
if rmd=13 then t$="D"
if rmd=14 then t$="E"
if rmd=15 then t$="F"
else
t$=str$(rmd)
endif
else
t$=str$(rmd)
endif
b$=b$+t$
until v<=0
for l=len(b$) to 1 step -1
res$=res$+mid$(b$,l)
next i
endfunction res$
function value2baser(v,base)
a$=value2basermain$(v,base,"")
endfunction a$
function value2basermain$(v,base,res$)
if v > 0
rmd = v mod base
v2 = v / base
`print v; ", ";v2; ", ";rmd
v = v2
if base = 16
if rmd >=10 and rmd<=15
if rmd=10 then t$="A"
if rmd=11 then t$="B"
if rmd=12 then t$="C"
if rmd=13 then t$="D"
if rmd=14 then t$="E"
if rmd=15 then t$="F"
else
t$=str$(rmd)
endif
else
t$=str$(rmd)
endif
res$=res$+t$
`print t$;", ";res$
res$=value2basermain$(v,base,res$)
endif
for l=len(res$) to 1 step -1
result$=result$+mid$(res$,l)
next i
endfunction result$
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others