Code Editor


Standard Input (For "," commands)

Console Output



History & Background

Brainfuck was designed in 1993 by Swiss physics student Urban Müller. His primary objective was to craft a programming language capable of being executed by the absolute smallest compiler possible.

Müller drew heavy inspiration from FALSE, an esoteric language created by Wouter van Oortmerssen that possessed a compiler size of 1024 bytes. Müller succeeded in surpassing this goal by writing an Amiga OS compiler for Brainfuck that measured under 200 bytes in size.

Despite relying on only 8 single-character commands, Brainfuck is Turing-complete. This means that, given sufficient memory and execution time, it possesses the same computational power as modern languages like Python, C, or JavaScript.


Detailed User Manual & System Architecture

1. Memory Architecture

The runtime environment consists of an array of 30,000 memory cells, often referred to as the tape. Each cell holds an 8-bit unsigned integer (a numerical range from 0 to 255). When a cell value exceeds 255, it wraps around to 0. Decrementing past 0 wraps back around to 255.

2. The Data Pointer

A mobile internal pointer tracks the currently active cell. All arithmetic operations (+ and -) and output/input instructions (. and ,) apply strictly to whichever cell the data pointer currently targets.

3. Loop Mechanics

Loops are declared using bracket pairs ([ and ]):

  • When encountering [, the engine inspects the current cell. If the cell contains 0, execution skips forward past the corresponding ]. If non-zero, execution continues into the loop.
  • When encountering ], the engine inspects the current cell. If the cell is non-zero, execution jumps back to the corresponding opening [. If zero, execution drops out of the loop.

4. Character Encoding (ASCII)

The output command (.) does not print raw integers. Instead, it translates the cell's numeric value into its matching symbol according to the ASCII table (e.g., Value 65 = 'A', Value 66 = 'B', Value 48 = '0', Value 10 = Newline).

5. Code Rules & Comments

Any character in the source code that is not one of the 8 core commands (> < + - . , [ ]) is treated as a non-executing comment. Caution: Do not use any of the 8 command characters inside commentary text, as they will still execute.


Command Reference Table
Symbol Name Action Description
> Shift Right Increments the data pointer to reference the next cell on the right.
< Shift Left Decrements the data pointer to reference the previous cell on the left.
+ Increment Adds 1 to the numeric value stored in the current cell.
- Decrement Subtracts 1 from the numeric value stored in the current cell.
. Output Converts current cell value to an ASCII character and prints it.
, Input Prompts user for input and saves the character's ASCII value to current cell.
[ Loop Start Jumps past matching ] if current cell value is zero.
] Loop End Jumps back to matching [ if current cell value is non-zero.

Examples

Example 1: Generating and Printing 'WencesByte.net'

Code: ++++++++++[>++++++++++>+++++<<-]>-------------.++++++++++++++.+++++++++.-----------.++.++++++++++++++.>++++++++++++++++.<++++++.-----.---------------.>--------------------.<+++++++++.---------.+++++++++++++++.

Descriptive Walkthrough: We run a dual-multiplier loop to set Cell #1 to 100 and Cell #2 to 50 as base ASCII anchors. We then adjust cell values using relative differences to print the full string.

  1. ++++++++++ — Cell #0 is incremented to 10 to act as our loop counter.
    Tape State: [10, 0, 0]
  2. [>++++++++++>+++++<<-] — Multiplies the counter by 10 for Cell #1 and by 5 for Cell #2 over 10 iterations.
    Tape State: [0, 100, 50]
  3. >------------- . — Move to Cell #1, subtract 13 to reach ASCII 87, and output W.
    Tape State: [0, 87, 50]
  4. ++++++++++++++ . — Add 14 to Cell #1 to reach ASCII 101, and output e.
    Tape State: [0, 101, 50]
  5. +++++++++ . — Add 9 to Cell #1 to reach ASCII 110, and output n.
    Tape State: [0, 110, 50]
  6. ----------- . — Subtract 11 from Cell #1 to reach ASCII 99, and output c.
    Tape State: [0, 99, 50]
  7. ++ . — Add 2 to Cell #1 to reach ASCII 101, and output e.
    Tape State: [0, 101, 50]
  8. ++++++++++++++ . — Add 14 to Cell #1 to reach ASCII 115, and output s.
    Tape State: [0, 115, 50]
  9. >++++++++++++++++ . — Move to Cell #2, add 16 to reach ASCII 66, and output B.
    Tape State: [0, 115, 66]
  10. <++++++ . — Move back to Cell #1, add 6 to reach ASCII 121, and output y.
    Tape State: [0, 121, 66]
  11. ----- . — Subtract 5 from Cell #1 to reach ASCII 116, and output t.
    Tape State: [0, 116, 66]
  12. --------------- . — Subtract 15 from Cell #1 to reach ASCII 101, and output e.
    Tape State: [0, 101, 66]
  13. >-------------------- . — Move to Cell #2, subtract 20 to reach ASCII 46, and output ..
    Tape State: [0, 101, 46]
  14. <+++++++++ . — Move back to Cell #1, add 9 to reach ASCII 110, and output n.
    Tape State: [0, 110, 46]
  15. --------- . — Subtract 9 from Cell #1 to reach ASCII 101, and output e.
    Tape State: [0, 101, 46]
  16. +++++++++++++++ . — Add 15 to Cell #1 to reach ASCII 116, and output t.
    Tape State: [0, 116, 46]

Example 2: Zeroing Out a Memory Cell

Code: [-]

Descriptive Walkthrough: This standard idiom resets whatever value exists in the current cell back to 0, regardless of what value it started with.

  1. Assume Cell #0 currently holds the value 5.
  2. [ — Checks Cell #0. Value is 5 (non-zero), so enter loop.
  3. - — Decrement Cell #0 value by 1 (value becomes 4).
  4. ] — Checks Cell #0. Value is 4 (non-zero), jump back to [.
  5. (Loop repeats until value drops to 0) — Once Cell #0 hits 0, the loop terminates and execution proceeds.

Example 3: Value Transfer (Addition)

Code: +++>++[<+>-]

Descriptive Walkthrough: Transfers the numerical value stored in Cell #1 into Cell #0, combining their contents.

  1. +++ — Set Cell #0 to 3.
  2. >++ — Move to Cell #1 and set value to 2.
    Tape State: [3, 2, 0]
  3. [ — Check Cell #1. Value is 2 (non-zero), enter loop.
  4. <+ — Move to Cell #0 and add 1 (Cell #0 becomes 4).
  5. >- — Move back to Cell #1 and subtract 1 (Cell #1 becomes 1).
  6. ] — Repeat loop. Cell #0 gets incremented to 5, Cell #1 drops to 0.
  7. Loop terminates because Cell #1 is now 0. Cell #0 holds the sum (3 + 2 = 5).
    Tape State: [5, 0, 0]

ASCII Table
Decimal Code Symbol / Character
0NUL (Null character)
1SOH (Start of Header)
2STX (Start of Text)
3ETX (End of Text)
4EOT (End of Transmission)
5ENQ (Enquiry)
6ACK (Acknowledge)
7BEL (Bell)
8BS (Backspace)
9TAB (Horizontal Tab)
10LF (Line Feed)
11VT (Vertical Tab)
12FF (Form Feed)
13CR (Carriage Return)
14SO (Shift Out)
15SI (Shift In)
16DLE (Data Link Escape)
17DC1 (Device Control 1)
18DC2 (Device Control 2)
19DC3 (Device Control 3)
20DC4 (Device Control 4)
21NAK (Negative Acknowledge)
22SYN (Synchronous Idle)
23ETB (End of Transmission Block)
24CAN (Cancel)
25EM (End of Medium)
26SUB (Substitute)
27ESC (Escape)
28FS (File Separator)
29GS (Group Separator)
30RS (Record Separator)
31US (Unit Separator)
32(Space)
33!
34"
35#
36$
37%
38&
39'
40(
41)
42*
43+
44,
45-
46.
47/
480
491
502
513
524
535
546
557
568
579
58:
59;
60<
61=
62>
63?
64@
65A
66B
67C
68D
69E
70F
71G
72H
73I
74J
75K
76L
77M
78N
79O
80P
81Q
82R
83S
84T
85U
86V
87W
88X
89Y
90Z
91[
92\
93]
94^
95_
96`
97a
98b
99c
100d
101e
102f
103g
104h
105i
106j
107k
108l
109m
110n
111o
112p
113q
114r
115s
116t
117u
118v
119w
120x
121y
122z
123{
124|
125}
126~
127DEL (Delete)
Memory Registers (Binary)