BCDFuck takes a stream of bytes and reads each byte as two BCD-encoded 4-bit words. Like other Brainfuck variants, BCDFuck operates on an array of cells, which in this case are 4 bits wide. The digits 0-9 are entered directly into the cells while the six 'wasted' states of 4-bit BCD encoding are translated into brainfuck-like instructions that act on the aforementioned array. Since any 4-bit word is a valid BCDFuck instruction, it would follow that all cells can be executed (as long as potential problems like unbalanced brackets can be ignored).
Each 4-bit word, represented by its corresponding hexadecimal digit, manipulates the cell array as follows
- 0 through 9 add the corresponding value to the current cell, and advances the cell pointer to the next cell. Thus, 0 is equivalent to > in Brainfuck. All cells in the cell array start with 0 as their default value, and wrap around when they are incremented beyond the limits. The upper limit of a cell is naturally F, and not 9.
- A moves the cell pointer to the previous cell, and is thus equivalent to < in brainfuck. Thus, 1A increments the value in a cell and 9A 6A decrements it, in a way similar to + and - in brainfuck, respectively.
- B and C act like the brainfuck's [ and ] operators, respectively.
- D acts like brainfuck's , operator. However, in this case it reads a byte from the input stream and buffers it until both the high and the low word are read, and in that order
- E acts like . in brainfuck, sending a word to the output stream. The order of output mirrors the order of input above, and an incomplete pair will be padded with a 0 if the program exits before the pair can be completed
- F is the Freaky Friday operator. It swaps the program array with the cell array so that their roles are reversed until another F swaps it back, much like the X operator in Braintwist
4A E4 AE 7A 7A E7 A8 AE 1A E6 AE 5A 5A E6 AE 5A 5A E4 A5 AE 3A E0 EA 3A E2 AE 7A 8A E4 A5 AE 8A E5 A6 AE 4A E6 AE 5A 5A E7 A7 AE 7A 7A E7 A8 AE 0E A4 A5 AE
Turing completeness proof
This conversion allows any 8-bit brainfuck program to be run on BCDFuck. It doesn't use the
|Eight bit BF Command||BCDFuck Commands|
||01 AA 1A B0 8A 7A C0 B8 A7 01 AA CA A|
||01 AA B0 8A 7A C0 B8 A7 08 A7 AA CA A8 A7 A|
||00 0E AA AE|
||00 0D AA AD|
||01 AA B0 8A 7A C0 B8 A7 1B A8 A7 AC AB AC 0B 8A 7A A1 CC A8 A7 AB 1A A|
||01 AA B0 8A 7A C0 B8 A7 1B A8 A7 AC AB AC 0B 8A 7A A1 CC A8 A7 AC A|