22 lines
369 B
Plaintext
22 lines
369 B
Plaintext
rem - Return binary representation of n as a string
|
|
def fn.bin$(n%)
|
|
s$ = ""
|
|
while n% > 0
|
|
if (n% - (n% / 2) * 2) = 0 then \
|
|
s$ = "0" + s$ \
|
|
else \
|
|
s$ = "1" + s$
|
|
n% = n% / 2
|
|
wend
|
|
fn.bin$ = s$
|
|
return
|
|
fend
|
|
|
|
rem - exercise the function
|
|
|
|
print "5 = "; fn.bin$(5)
|
|
print "50 = "; fn.bin$(50)
|
|
print "9000 = "; fn.bin$(9000)
|
|
|
|
end
|