Friday, 17 November 2017

Brainfuck: print ASCII Table

ASCII table has 256 (from 0 to 255) characters. To print all the characters of ASCII table, I would like to go with below approach.

Step 1: File the 1st cell with value 255. Below snippet do that.
+++++++++++++++++  # Initialize the 0th to 17
>
++++++++++++++  # Initialize the 1st cell to 15
[
 -
 <
 +++++++++++++++++   # Increment the first cell by 17
 >
]

Step 2: Print the 1st cell content and decrement the value, repeat step2, until it reaches to 0. Below snippet do that.

[.-]

Find the below working application

+++++++++++++++++  # Initialize the 0th to 17
>
++++++++++++++  # Initialize the 1st cell to 15
[
 -
 <
 +++++++++++++++++   # Increment the first cell by 17
 >
]

<      Move the data pointer to 0th cell

[.-]

When you ran above application, it prints the ASCII table from bottom(255) to top (0).




Previous                                                 Next                                                 Home

No comments:

Post a Comment