Older Version
Newer Version
bshipps64
Feb 18, 2006
DecToBin$ function
Simple function with (very) simple demo program illustrating how to build a string containing the binary representation of a decimal number.[loop]
input a$
if a$ = "" then end
print DecToBin$(val(a$))
goto [loop]
function DecToBin$(decNum)
if (decNum) then
decNum = abs(decNum)
if (decNum = int(decNum))) then
do
if (decNum and 2^x) then
DecToBin$ = "1" + DecToBin$
else
DecToBin$ = "0" + DecToBin$
end if
x = x + 1
loop until (2^x > decNum)
else
DecToBin$ = "0"
end if
end if
end function