Thisislegal.com

:[ Login ]:

welcome, please log-in:




 Remember Me  ?
About: Remember Me
Ticking this box will make the site remember you for 24 hours. However, each time you visit the site this time is renewed, so if you are a regular visitor you will stay logged in.


Register An Account
Forgot Password?

:[ Forums ]:
Latest post in: Challenge Help
topic:
real 4
by: Karlito
:[ Welcome ]:

The BrainFuck Language

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



Was this tutorial helpful? please rate:

You Must Login To Vote




Previous Tutorial  |  Next Tutorial


Tutorial By Raduce

Comments:

GuestReply 
0


confusing
TimseReply 0
What is this spam?
RaduceReply 
0


Thanks. P.S. These aren't real surprises.A surprise would be making a tut about how to turn soda into a rocket.
sOwLReply 
0


heh i surelly didnt know about this stuff biggrin.gif sounds cool i wanna try it some time. Your full of surprises RaducE
t0mmy9Reply 
0


a note that this language was invented as a challenge to try and confuse programs, its not surprising if this confuses you. Impressive you fully understand it RaducE smile.gif


Submit Comment:


Human test. Enter "zJa"



Who's online: flipp

Click here to Vote!    Firefox 3  Opera Web Browser  Valid XHTML 1.0 Transitional

Home | Challenges | Forums | Contact | About (Disclaimer)
Copyright © 2007-11 Thisislegal.com, All Rights Reserved

 
:[ ShoutBox ]:
Guest - Login to post comments


Karlito:
crack it
niken:
how get wpa password
sidolo:
maybe you have the wrong kind of network card?
12345:
why doesnt my airodump detect wireless networks?
Andrew3726:
IDA Pro, i think smile.gif
ksydfius:
app challenge 4? whats the best 16-bit debugger?
dot_Cipher:
The internet says hi smile.gif
Pages: 1, 2...195
Goto: