esolang

Bitflipper

Five instructions on a row of bits, and below bit 0 lies the program itself.

gapples2, 2022 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: Hi

The idea

gapples2 made Bitflipper on 23 March 2022. Memory is a row of bits that all start at 0, and the only way to change one is to flip it. To print a letter you flip the bits of a byte until they spell its code, then print the byte. The Hello, World! program takes 30 flips and 13 prints.

Read the story

Negative addresses reach into the source code, so a program can rewrite its own lines while it runs. The specification does not say how they map. This implementation puts the source just below bit 0, one byte per character, so bit -1 is the last bit of the last character.

The machine

InstructionDoes
FLIP XFlip bit X
SKIP XSkip the next line if bit X is 1
JUMP XGo to line X
OTPT XPrint the byte that starts at bit X
INPT XRead a character into the byte that starts at bit X
#A comment to the end of the line

A byte is eight bits with the highest first. Lines count from 0, blank and comment lines too. A jump to a line that is not there ends the run, which is how the example programs stop with JUMP -1. At the end of the input INPT reads 0.

Example

H is 01001000, so flipping bits 1 and 4 makes it.

H is 01001000, so flipping bits 1 and 4 makes it. Two more flips turn it into i, which is 01101001.

This program edits itself. The last character of its source is the 0 of JUMP 0, which OTPT -8 prints. FLIP -3 turns that 0 into a 4, so the jump that would loop forever now goes to line 4, which does not exist, and the run ends.

Expected: 04

The cat reads a character into bits 1 to 8, tests the bits one at a time and jumps to the print as soon as one is 1. When all eight are 0 it has read a null byte and stops. The truth machine tests its input bit by bit the same way and stops unless the bits are 0011000x. On 0 it prints 0 and stops. On 1 its last line jumps to line 43, but the program has 39 lines, so it prints 11 and stops.

Patterns it teaches

Further

Self-modifying

Write your own in Run Convert a program from Bitflipper

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run bitflipper program.txt --input '0'

The program is long; save it as program.txt first.

shib manual bitflipper

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/bitflipper.js

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

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