Write some code that takes a single string as input and outputs MSB-set aligned ASCII.
Only ASCII characters less than 128 (0x80) will be in the input. The output format is generated as follows:
- For each character convert it to its binary representation, remove the MSB (always
0
in the input) and then add a delimiter-bit (X
) to both ends. The value will now be 9 bits long and both begin and end inX
- Output each character in order, MSB to LSB, making sure that the MSB of each output byte is either
1
orX
- If the MSB of the next byte would normally be
0
, output the fewest.
s needed between two consecutiveX
s to align the MSB with a1
orX
- Output the data as binary digits, with
X
for each delimiter and.
for each padding bit - At the end of the data, write a
.
after the lastX
, then as many.
s as necessary to complete the last byte - Separate each byte (group of 8 digits) with a single whitespace character (space, tab, newline, etc.)
- A whitespace character at the end of the last output line is optional
- Empty input must produce
........
as the output - Your code must work on any length strings that your language can handle and at least 255 characters
Input: Hello, World!
Bytes -> Delimited -> * Output Start and End of each character
01001000 X1001000X X1001000 'H'
01100101 X1100101X XX110010 'e' 'H'
01101100 X1101100X 1X.X1101 'l' 'e'
01101100 X1101100X 100XX110 'l' 'l'
01101111 X1101111X 1100X.X1 'o' 'l'
00101100 X0101100X 101111X. 'o'
00100000 X0100000X X0101100 ','
01010111 X1010111X X.....X0 ' ' ','
01101111 X1101111X 100000XX 'W' ' '
01110010 X1110010X 1010111X 'W'
01101100 X1101100X X1101111 'o'
01100100 X1100100X X.X11100 'r' 'o'
00100001 X0100001X 10XX1101 'l' 'r'
100X..X1 'd' 'l'
100100X. 'd'
X0100001 '!'
X....... '!'
The *
marks the Most Significant Bit in the output. Each bit in this column is either 1
or X
. Removing any number of .
s would cause either a 0
or .
in the MSB column. If the input was Hello, W
the last byte output would be ........
.
As usual, lowest score wins!
0
or.
is allowed in the leftmost column (MSB). \$\endgroup\$