Brainfuck Reference

Overview

Brainfuck is a minimalist esoteric programming language created by Urban Müller in 1993. It operates on a tape of memory cells using a data pointer, with only 8 commands. Despite its simplicity, it is Turing complete.

Data Types

All data is stored as unsigned 8-bit integers (u8, range 0–255) with wrapping arithmetic. Incrementing 255 gives 0; decrementing 0 gives 255.

Syntax

A Brainfuck program consists of the 8 command characters listed below. All other characters are ignored and can be used as comments.

Commands

CommandDescriptionEffect
>Move rightIncrement the data pointer by one
<Move leftDecrement the data pointer by one
+IncrementIncrement the byte at the data pointer (wraps 255 → 0)
-DecrementDecrement the byte at the data pointer (wraps 0 → 255)
.OutputOutput the byte at the data pointer as an ASCII character
,InputRead one byte of input into the cell at the data pointer (0 if no input)
[Jump forwardIf the byte at the data pointer is 0, jump to the matching ]
]Jump backIf the byte at the data pointer is nonzero, jump to the matching [

Examples

Hello World

++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]
>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

Cat (echo input)

,[.,]

Add 2 + 3

++           Set cell 0 to 2
>+++         Set cell 1 to 3
<[->+<]      Move cell 0 into cell 1 (addition)
>            Move to cell 1 (now 5)
++++++++++++++++++++++++++++++++++++++++++++++++.  Add 48 for ASCII '5'

Simple loop: count to 5

+++++++      Set cell 0 to 7
[>+++++++<-] Multiply into cell 1: 7×7 = 49 (ASCII '1')
             Cell 0 is now 0
<            (already at cell 0)
+++++        Set cell 0 to 5 (loop counter)
[            While cell 0 is nonzero
  >.+        Print cell 1, then increment it
  <-         Decrement counter
]

Constraints