|
Comments
|
Base expansion: the technique to
expand a value. It is quite general. One can expand
by any base and with different layout - (0 : N-1),
or (1 : N), or (0 : N-1)+1.
Here noted
(0 : N-1) a usual expansion, like 5 binary is 101;
(1 : N) an expansion where zeros take over the higher
digit, e.g. 1 2 3 4 5 6 7 8 ... binary are
1, 2, 11, 12, 21, 22, 111, 112, ... ;
(0 : N-1)+1 is a usual expansion where every digit
is incremented by 1.
The second and the third cases may especially be useful for brainfuck since sometimes it is not desirable to have zeros.
The technique can be seen in this example:
[ -<+> [ -<+> [ -<+> [ -<+> [ -<+> [ -<+> [ -<+> [ >+< <[-] ] ] ] ] ] ] ] >]This is the expansion on base 7 with the second case (1 : N).
The third case is used for a program printing decimal ASCII values of the input characters.
----------------------------------------------- this program prints ascii values of input chars >>, [ [ -<++> [ -<+> [ -<+> [ -<+> [ -<+> [ -<+> [ -<+> [ -<+> [ -<+> [ <[-]+> ->+< [<-] ] ]]]]]]]] >] print digits <<[>++++++[<++++++++>-]<-.[-]<] print eol ++++++++++.[-]>> ,] -----------------------------------------------
start with 0 1 'x >+>++ [ -[ -[ -[ [-] <- case 4 or more <,.> > ] <[- case 3 <,+.> ]> ] <[- case 2 <,++.> ]> ] <[- case 1 <,+++.> ]> ] <[- case 0 <,++++.> ]>This program will double increment the input character executing 'case 2'.