Introduction
BitShift is an esolang, created by me, to output strings. Sounds boring, is boring. However, the only instructions available to BitShift are 0
and 1
. Therefore it can be challenging to golf in it. To make matters even more interesting, the language only supports 4 bitshifting instructions, a clear, a print and an input instruction.
How it works
BitShift is written by alternating 0
and 1
characters. Once the interpreter finds 2 of the same characters in a row, it will perform an instruction based on the amount of non-alternating characters preceding it.
010010110001010
will perform the operations 3 4 2 1 5
010 0101 10 0 01010
here, the non-alternating characters are seperated by a spacebar for readability.
The interpreter can be found here
Operations
All operations are performed on one single value. BitShift does not know of a stack.
BitShift programs initially start with a value of 0. This value can range from 0-255 and overflows at -1 and 256
1 Shift the value 1 bit to the left (0000 0001 > 0000 0010)
2 Shift the value 1 bit to the right (0000 0010 > 0000 0001)
3 XOR the value with 1 (0000 0000 > 0000 0001)
4 XOR the value with 128 (0000 0000 > 1000 0000)
5 Set the value to 0
6 Convert the value to a character and print it
7 Read a character from user input and set the value to it
Challenge
Your task is to create a program which can convert an input string to the shortest possible BitShift program which will output that string when run.
Rules
- You are not allowed to use the
7
operation - Your program takes only one input argument, which is the string to convert
- Your program will output the translated BitShift program to STDOUT
- You can use any kind of built-in function in your preffered language
- You can use any kind of language, as long as it's created before this date
Scoring
This is a metagolf.
The person who can create the shortest BitShift program will win this challenge. In case of a tie, the lowest byte count will win.
The input string (ISO 8859-1) you should base your answer on is:
This is a string, meant to test the effectiveness of your program. Here are some special characters to make matters interesting: Æ Ø ß. How meta! :D
The special characters used are Æ Ø ß
Please post the output of your program in your answer, so that it can be tested for validation.
The following is an example solution. Obviously, this is a terrible solution.
Javascript, 594 bytes, 4275 characters
var flag = true;
var input = prompt();
var output = ""
for (n in input) {
var c = input.charCodeAt(n).toString(2);
while (c.length < 8) {
c = "0" + c;
}
for (var i = 0; i < 8; i++) {
if (c[i] == "1") {
output += flag ? "010" : "101";
}
if (i < 7) output += flag ? "0" : "1";
}
for (var z = 0; z < 6; z++) {
output += flag ? "0" : "1";
flag = !flag;
}
flag = !flag;
for (var z = 0; z < 5; z++) {
output += flag ? "0": "1";
flag = !flag;
}
flag = !flag;
}
console.log(output);