Last active
January 4, 2016 05:09
-
-
Save miguelfrde/8573568 to your computer and use it in GitHub Desktop.
Brainfuck program to generate next binary number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- initial mark (FF) | |
read input 49 = 1 and 48 = 0 (q0) | |
>>,[>,<-------- -------- -------- -------- -------- -------- >] | |
- final mark (FF) | |
<[-<] change ones for zeros until a zero is found (q1) | |
+ change zero for one (q1 to q2) | |
< ignore all characters until FF is found (q2) | |
+ increase by one (ensures that the data pointer moves until FF is found) | |
[ if the byte at the data pointer is zero then FF was found | |
- it wasn't zero decrease it | |
< move left to check next bit | |
+ increase by one as before | |
] begin printing | |
>-[>-]+ ensure that no leading 0s are printed | |
+ increase by one to ensure that the byte at the data pointer is not FF | |
[ | |
add 47 (to print the character as either 0 or 1) | |
++++++++ ++++++++ ++++++++ ++++++++ ++++++++ +++++++ | |
. print character | |
> go to next character | |
+ add 1 as before | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment