esolang

BitChanger

Brainfuck squeezed down to one-bit cells and four commands, with input and output hidden in the tape itself.

Jeffry Johnston, 2000 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 3 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: A

The idea

Jeffry Johnston made BitChanger in December 2000 by shrinking brainfuck step by step. First every cell holds one bit, so + and - both flip it. Then "flip" and "move right" merge into one command, }. Moving right without a change is }<}: flip the next bit, step back, then step right again and flip it back.

Read the story

Last, . and , disappear. Input and output are mapped onto a few fixed bits of the tape, so the language keeps only } < [ ].

The machine

A tape of bits, all 0, with the head on bit 16.

CommandDoes
}Move right, then flip the bit there
<Move left
[If the bit is 0, jump past the matching ]
]Jump back to the matching [

The low bits of the tape are the I/O port:

BitRole
5Moving right onto it does I/O (and does not flip it)
6Set to 1 when input has run out
71 = write, 0 = read
8–15The byte, most significant bit first

Every other character is a comment. Two handy idioms: <} flips the bit under the head, and }<} moves right without changing anything.

Example

The < run walks from bit 16 to bit 6, and }<} steps right onto bit 7 while <} flips it to 1: write mode.

The < run walks from bit 16 to bit 6, and }<} steps right onto bit 7 while <} flips it to 1: write mode. The same moves set bits 9 and 15, so bits 8–15 read 01000001, which is 65, A. Then the head walks back to bit 4, and the final } steps onto bit 5 and writes the byte.

Expected: Hi

Two letters, one write each. H is 01001000, and flipping bits 10 and 15 turns it into i, 01101001.

Expected: cat

A cat program. Bit 16 keeps the loop going. Each turn reads a byte (bit 7 is 0) and clears bit 16. Then it flips bit 6, so a 1 there means "not at the end". Inside that one-time loop it writes the byte, sets bit 16 again and flips bit 6 back to 0, which ends the inner loop.

Patterns it teaches

  • Turing tarpit: four commands and one-bit cells. A loop can only test for a 1, so every "if" needs a spare bit that the body clears.
  • Turing completeness: it maps one-to-one onto Boolfuck (+ is }<, > is }<}), which can run brainfuck.
  • Encoding tricks: memory-mapped I/O puts a whole I/O system into the tape itself.

Try this

  1. Print B (01000010).
  2. Write [<], which moves left while the bit is 1, and use it to find the end of a row of ones.
  3. Hard: print * five times, using a row of five 1 bits as the counter.

Further

BitChanger builds on Brainfuck.

Brainfuck derivatives

Cell-based

Write your own in Run Convert a program from BitChanger

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: bitchanger.

Command line

shib run bitchanger -e '<<<<<<<<<<}}<}}<}}<}<}}<}}<}<}}<}}<}<}}<}}<}}<}<}}<}<}}<}<}}<}<}}<}<}[<}<[<]<<<<<<<<<<<<}}<}}<}}<}}<}}<}}<}}<}}<}}<}}<}}<}}<}[}<}]<]'
shib manual bitchanger

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/bitchanger.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org