Commodore VIC-20/C64/128 and TheC64Mini, 101 tokenized BASIC bytes
Here is the obfuscated listing using Commodore BASIC keyword abbreviations:
0dEfnb(x)=sG(xaNb):inputa$:fOi=1tolen(a$):b=64:c$=mI(a$,i,1):fOj=0to6
1?rI(str$(fnb(aS(c$))),1);:b=b/2:nEj:?" ";:nE
Here for explanation purposes is the non-obfuscated symbolic listing:
0 def fn b(x)=sgn(x and b)
1 input a$
2 for i=1 to len(a$)
3 let b=64
4 let c$=mid$(a$,i,1)
5 for j=0 to 6
6 print right$(str$(fn b(asc(c$))),1);
7 let b=b/2
8 next j
9 print " ";
10 next i
The function fn b
declared on line zero accepts a numeric parameter of x
which is AND
ed with the value of b
; SGN is then used to convert x and b
to 1
or 0
.
Line one accept a string input to the variable a$
, and the loop starts (denoted with i
) to the length of that input. b
represents each bit from the 6th to 0th bit. c$
takes each character of the string at position i
.
line 5 starts the loop to test each bit position; right$
is used in line 6 to remove a auto-formatting issue when Commodore BASIC displays a number, converting the output of fn b
to a string; asc(c$)
converts the current character to its ascii code as a decimal value.
Line 7 represents the next bit value. The loop j
is ended before printing a space, then the last loop i
is ended.