27
2
Reverse and Invert a String
Challenge
In this challenge. You'll be writing a program which will output or return the input, reversed and inverted.
First, each character should be converted to its character code. Then, that should be converted to base-2. Following, that string should be reversed. After, the string should be inverted (1 -> 0 and 0 -> 1). Finally, that should be converted back to base 2 and then converted back to a character. If an character results to be an unprintable, you may optionally output it but they do not have to be removed.
H -> 72 -> 1001000 -> 0001001 -> 1110110 -> 118 -> v
e -> 101 -> 1100101 -> 1010011 -> 0101100 -> 44 -> ,
l -> 108 -> 1101100 -> 0011011 -> 1100100 -> 100 -> d
l -> 108 -> 1101100 -> 0011011 -> 1100100 -> 100 -> d
o -> 111 -> 1101111 -> 1111011 -> 0000100 -> 4 -> (unprintable)
, -> 44 -> 101100 -> 001101 -> 110010 -> 50 -> 2
-> 32 -> 100000 -> 000001 -> 111110 -> 62 -> >
W -> 87 -> 1010111 -> 1110101 -> 0001010 -> 10 -> (newline)
o -> 111 -> 1101111 -> 1111011 -> 0000100 -> 4 -> (unprintable)
r -> 114 -> 1110010 -> 0100111 -> 1011000 -> 88 -> X
l -> 108 -> 1101100 -> 0011011 -> 1100100 -> 100 -> d
d -> 100 -> 1100100 -> 0010011 -> 1101100 -> 108 -> l
! -> 33 -> 100001 -> 100001 -> 011110 -> 30 -> (unprintable)
Scoring
Shortest code in bytes wins.
-15% Bonus: if your program removes un-printables from the output. This must be at least all characters below 32 except newlines (char 10)
I need to get my Simplex interpreter working again XD
GBktnkZs
– Conor O'Brien – 2015-11-06T01:13:22.160So the characters in the string aren't reversed, but the bits in each character are? – xnor – 2015-11-06T01:36:27.957
Just to be sure: for 0010000 is the bit reverse 0000100 or 00001? – Digital Trauma – 2015-11-06T02:37:55.900
@DigitalTrauma If the binary code is
0010000
, it should be treated as10000
so the reverse would be00001
– Downgoat – 2015-11-06T03:06:37.030For the bonus, do we need to leave newlines, or can we remove anything below
00010000 == space
? – ETHproductions – 2015-11-06T04:01:59.773@ETHproductions clarified, you should leave newlines – Downgoat – 2015-11-06T04:05:43.910
2Can we assume just ASCII (as your examples), or should this work for whatever is a character in my language? (Also, if a language uses a different character code, should I use this instead of ASCII/Unicode)? – Paŭlo Ebermann – 2015-11-06T17:30:08.060
32 and below? You want to remove spaces too? – aditsu quit because SE is EVIL – 2015-11-06T18:34:50.030
@PaŭloEbermann if your language supports only ASCII then you may support only ASCII otherwise you should support the whole character set of your language – Downgoat – 2015-11-06T19:18:38.377
@aditsu nope spaces are fine :p Fixed – Downgoat – 2015-11-06T19:19:00.330
You say "or return" but you only say "a program." Is a function allowed? – Level River St – 2015-11-06T20:12:03.760
@steveverrill of course – Downgoat – 2015-11-06T20:19:28.067
Also, the title is a bit misleading, because I would have supposed that the whole string is reversed, too, not just each individual character. – Paŭlo Ebermann – 2015-11-06T21:52:24.613
So you want ASCII 10 and 32 to 126 printed in the bonus version? Are 9 to 13 allowed? – Titus – 2017-04-15T22:13:49.150