esolang

BitShift

Only zeroes and ones, and what counts is how long they keep taking turns.

Bas, 2015 · Turing complete: no · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hi

The idea

Bas made BitShift in 2015 to remember the days when computers only understood zeroes and ones. A program is a string of bits, and the bits themselves mean nothing. What matters is a run of bits that alternate, 0101 or 10. Two equal bits in a row end a run, and its length picks the command. It does not matter whether a program starts with 0 or 1.

Read the story

So 0101011010011101011 reads as 010101 1010 01 1 10101 1, the commands 6, 4, 2, 1, 5 and 1.

The machine

There is one byte, from 0 to 255, and it starts at 0. No stack, no tape and no loops.

RunDoes
1Shift the byte one bit left
2Shift it one bit right
3Flip its lowest bit, XOR 1
4Flip its highest bit, XOR 128
5Set it to 0
6Print it as a character
7Read a character into it

Any other character, an empty program or a run longer than 7 is an error. The specification's Common Lisp interpreter also stops when 7 finds no input left, and so does this implementation.

Example

Each letter is built up from 0 with flips and shifts, then printed.

Each letter is built up from 0 with flips and shifts, then printed. H is 72, binary 1001000. In this program that is 5, then 3 1 1 1 3 1 1 1, then 6. i follows the same way, and the whole program is 52 bits.

The Hello, World! program takes 211 bits and has a slip. After the comma, 44, it flips the low bit to get 45 and shifts left five times. That gives 160, not 32, so the program prints byte 160, a no-break space in Latin-1, where the space should be.

The cat is a run of 7 that reads, then a run of 6 that prints.

Expected: a

Patterns it teaches

Further

Also in Turing tarpits

Write your own in Run Convert a program from BitShift

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run bitshift -e '0101010010101' --input 'a'
shib manual bitshift

Source

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

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

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