Here's a piece of code I knocked up in couple of mins which converts decimal whole numbers to either binary, hex, octal. of course we have functions hex$ and bin$ but wanted to test out octal (base 8) also.
I wrote a recursive function which worked to a point, but "endfunction res$" for example did not return the final string, and am working on a differernt way to get it to return correctly.
No code to handle negative numbers yet i.e. the complement system
+ Code SnippetRem Project: value2base_v0.1
Rem Created: Tuesday, July 06, 2021
Rem ***** Main Source File *****
sync on : sync 30 : sync
decval=255
base=2
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$