This code first gets (almost) the binary representation of a number then it says whether to add or not based on that representation.
Example:
input:
5
output:
don't add
add
Thus, you start with 1, then you multiply by 2, then you don't add 1, then you multiply by 2, and add 1 again. You get 5.
With an input of n% = 3, you start with 1, multiply by 2, then add 1. Thus you get 3.
CLS
n% = 9
IF n% < 1 THEN PRINT "Error": SYSTEM
DO
IF n% = 1 THEN EXIT DO
IF n% AND 1 THEN n$ = "1" + n$ ELSE n$ = "0" + n$
n% = n% \ 2
i% = i% + 1
LOOP
n% = 1
FOR j% = 1 TO i%
n% = n% * 2
IF MID$(n$, j%, 1) = "1" THEN n% = n% + 1: PRINT "add" ELSE PRINT "don't add"
NEXT j%
-Agamemnus