bitch
One accumulator and only bitwise operations. Even adding two numbers is a loop of XOR, AND and shifts.
Helen, 2019 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 4 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Helen made bitch in 2019, after Arphimigon's BITCHWISE. There is one place to keep a value, the accumulator, and the only arithmetic is AND, OR, XOR, NOT and shifts. There is no +. The addition program repeats "XOR for the sum bits, AND and shift left for the carries" until the carry is 0.
Read the story
Two ideas make that possible. First, the bits that a right shift pushes out are not lost. They go onto a storage of bits, and a left shift pulls them back in, so the storage works as a stack. Second, an argument can be a whole instruction. ^]32 XORs the accumulator with itself shifted right by 32, worked out on a copy, so a value can meet a shifted version of itself without a second register.
The machine
An accumulator holding an integer without bounds, and a storage of bits.
| Instruction | Does |
|---|---|
#n | Set the accumulator to n, empty the storage |
&n \|n ^n | AND, OR, XOR with n |
~ | NOT |
]n | Shift right by n; the lost bits go on top of the storage |
[n | Shift left by n, filling from the top of the storage |
\ | Read into the accumulator, empty the storage |
/ | Print the accumulator |
> < | Mark a place, jump back to the last mark |
: ; | Run the next instruction only if the accumulator is 0, or only if it is not |
. | End the program |
Any n can be a number or an instruction, which runs on a copy. The spec reads and prints numbers; TIO runs all three interpreters with characters instead, and so does this implementation.
Example
The second is the addition program.
The second is the addition program. It reads ! (33) and parks it in the storage with ]32, then ORs in the second !. Inside the loop the two halves of the accumulator are combined into sum bits and carry bits until no carry is left. 33 + 33 is 66, B.
Patterns it teaches
- Turing tarpit: a stack of bits and a loop are enough for a Turing machine, which the specification builds.
- Encoding tricks: two numbers live in one accumulator, in its upper and lower 32 bits.
Further
- esolangs.org/wiki/Bitch
- Helen's interpreter: github.com/Helen0903/bitch; int-e's two others: github.com/int-e/bits
See also
Also in Turing tarpits
Write your own in Run Convert a program from bitch
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: bitch.
Command line
shib run bitch -e '#65]3[3/'shib manual bitchSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/bitch.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org