Boolfuck
Brainfuck where every cell is one bit, and even input and output arrive one bit at a time. Printing a letter takes eight instructions.
Sam Hughes, 2004 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 1 example and 1 known program · Hello World on Try It Online: identical except the line end · Test method
Run it
Hello World
Expected output
Hello, world!
Output
The idea
Brainfuck cells hold bytes. In Boolfuck they hold bits, so + and - are the same thing (flip) and there is nothing to wrap.
Read the story
Unlike Smallfuck, which drops I/O altogether, Boolfuck keeps it, at bit size. , reads one bit of input and ; writes one bit of output. The bits are packed into bytes, lowest bit first.
It is still Turing complete. Every Brainfuck program can be translated: each byte cell becomes a group of bit cells, and + becomes a small ripple-carry routine over the group. The translation is long but mechanical. That makes Boolfuck a neat demonstration that "byte" was never essential.
The machine
A tape of bits, all 0, unbounded, and a pointer. An output buffer of bits, flushed as bytes.
| Char | Does |
|---|---|
+ | Flip the current bit |
> < | Move the pointer right or left |
, | Read the next input bit into the current cell |
; | Append the current bit to the output |
[ | If the bit is 0, jump past the matching ] |
] | If the bit is 1, jump back to the matching [ |
Every other character is a comment. Bit order is little-endian: the first bit read or written is the lowest bit of the byte. (In this implementation, reading past the end of input gives 0s, and a final partial byte is padded with 0s.)
Example
Print A.
Print A. Its code is 65, binary 01000001, so lowest bit first it is 1 0 0 0 0 0 1 0. One cell is enough: flip it whenever the next bit differs, and write.
+; 1
+;;;;; 0 0 0 0 0
+; 1
+; 0
Echo one character: read a bit and write it back, eight times.
The Hello, world! on esolangs.org is a block of + and ; built the same way, one bit at a time.
Quirks
- A run stops after 3,000,000 steps.
Try this
- Print
Hi(72, 105) with as few instructions as you can. - Write a program that reads one character and prints it with the lowest bit flipped (
Abecomes@). - Hard:
catthat copies every byte until a zero byte. You will need eight cells per byte and a way to test "all eight are 0".
Patterns it teaches
- Turing tarpit: seven symbols, one bit per cell, still universal.
- Turing completeness: proved by translating Brainfuck into it, the standard way to show a new language is universal.
- Encoding tricks: output is a bit stream that happens to spell bytes. The program never sees a character, only the order of bits.
Further
- esolangs.org/wiki/Boolfuck
- The original page on qntm.org: qntm.org/boolfuck
- Siblings: Smallfuck (no I/O, finite tape), Brainfuck (bytes).
See also
Boolfuck builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from Boolfuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: boolfuck.
Command line
shib run boolfuck -e '
;;;+;+;;+;+;
+;+;+;+;;+;;+;
;;+;;+;+;;+;
;;+;;+;+;;+;
+;;;;+;+;;+;
;;+;;+;+;+;;
;;;;;+;+;;
+;;;+;+;;;+;
+;;;;+;+;;+;
;+;+;;+;;;+;
;;+;;+;+;;+;
;;+;+;;+;;+;
+;+;;;;+;+;;
;+;+;+;
'shib manual boolfuckSource
- Module
langs/classic.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org