Bitwise Scanner

From Esolang
Jump to navigation Jump to search

Bitwise Scanner is a bitwise language created by User:A. It is based on scanning a bitwise tape.

Commands

Command Description
(statements) Execute the code block composed of the statements if the current bit is 0.
{statements} Execute the code block composed of the statements if the current bit is 1.
[statements] Sequentially query the bitwise tape, from the lowest digit to the highest digit, executing the statements.
~ Multiply the current bit by -1 and add 1. Equivalent to flipping the bit.
X Stop the scanning.

The increment procedure

000->001
001->010
010->011
011->100

We can conclude that the algorithm is(without doing math):

If the lowest digit is zero,
    Flip the lowest bit
Otherwise(if the lowest bit is 1),
    scan from the lowest digit to the highest digit:
        If the current bit is 1,
            flip this bit
        Otherwise (current bit is 0)
            flip this bit and stop scanning

This can be achieved in Bitwise Scanner like this:

(~){[{~}(~X)]}

The decrement procedure

111->110
110->101
101->100
100->011
011->010
010->001

The main algorithm for this is:

If the lowest bit is 1:
    Flip the lowest bit
Otherwise(if the lowest bit is 0):
    Scan the binary array:
        If the current bit is 0:
            Flip the current bit
        Otherwise:
            Flip the current bit and stop scanning

This can be achieved as:

{~}([(~){~X}])

Computational Class

This language is not Turing complete, or even FSM complete, as it cannot store state from bit to bit. Consider, for example, a program that sets every bit to the previous bit's value. This would be impossible to do in Bitwise Scanner.

Interpreter

  • Common Lisp implementation of the Bitwise Scanner programming language.