Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

BrainFuck


BrainFuck

By ghostghost | 5933 Reads |
0     0

Programming in BrainFuck. By BobbyB.

This article is going to teach you the worlds most simple and hilarious language: BrainFuck.

Basically, all BrainFuck does is manipulate a huge line of 30000 bytes, with only 8 commands.

Just imagine a string of 30000 bytes. At the start of the program, there is a pointer at the one right

at the left. Now, we can move this pointer along the string of bytes with two operators:

-move the pointer to the next byte on the right < -move the pointer to the next byte on the left

Whilst at these bytes, we may either increase their values or decrease their values with these two

commands:

  • -increase the value of the byte at the pointer by one
  • -decrease the value at the byte at the pointer by one

Also, we can either input data in to these pointers, or out put data from these pointers, with two more

operators:

, -input ascii value of key pressed in to byte at the pointer . -output ascii value of the pointer as a character

So, a program to say 'Hello' could look something like this is BrainFuck:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Changes the value of the byte at the pointer to 72,or 'H' in ascii

. Outputs ascii the character of the byte at the pointer

+++++++++++++++++++++++++++++ Changes the value of the byte at the pointer to 101, or 'e' in ascii

. Outputs ascii the character of the byte at the pointer

+++++++ Changes the value of the byte at the pointer to 108, or 'l' in ascii

.. Outputs ascii the character of the byte at the pointer twice

+++ Changes the value of the byte at the pointer to 111, or 'o' in ascii

. Outputs ascii the character of the byte at the pointer

In BrainFuck, there is no need for comment marks, as any other characters other that the eight

characters used as commands are simply ignored.

Now, there are two more commands in BrainFuck, and these are loop commands, they are rather difficult

to get your head round at first, but soon become clear. They are

[ and ]

These work by the commands inside the [] commands being repeated until the byte the pointer was at just

before the [ operator becomes zero.

So, to print out a capital H thirty times, the BrainFuck code would look like this:

++++++++++++++++++++++++++++++ Make the value of the first pointer 30

Go to the next pointer on the right

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Make the value of the byte at this pointer 72, or 'H' in ascii

< Go back to the previous pointer

[ Start the loop

.<-] Make it so the value of the next pointer is displayed as an ascii character and the value of the

previous pointer is decreased by one, so when the letter has been displayed thirty times the first pointer reaches zero and the loop stops.

And finally, for one last BrainFuck program, we will take user input of one letter and the display it back again. The code is this:

,.

That's it. As soon as , assigns the ascii value of the key pressed to the pointer . displays it back again.

A good BrainFuck compiler can be found at http://home.arcor.de/partusch/html_en/bfd.html

That's all there is to this wonderful language.

Comments
ghost's avatar
ghost 18 years ago

What can you do with brainfuck?

ghost's avatar
ghost 17 years ago

wtf man? seriously. what can you do with this? why would you want to do something with this?

ghost's avatar
ghost 17 years ago

BrainFuck is really a nice language, its too bad that not more people use it. :P

ghost's avatar
ghost 17 years ago

what the fuck is this

ghost's avatar
ghost 17 years ago

kiyoura: I can assure you that pointer manipulation (however simplistic it may be, lol) is more advanced than clicking and dragging in Visual Basic. I'd also like to note that BobbyB is not 'noob' as you so willingly assumed.

ghost's avatar
ghost 17 years ago

I like the article since not much people use brainfuck, its a fun language.

and for all the people here who think it sucks, it gives you a good understanding of programming and logic and altho its not the best language to program in, you can see it as a great challenge.

ghost's avatar
ghost 15 years ago

lmfao this is great, should also be an article on malbolge :P