Inspired by the following XKCD comic:
In Missy Elliot's "Work It", part of the chorus goes as follows:
Is it worth it, let me work it
I put my thing down, flip it and reverse it
Bearing that in mind, I propose the following code golf challenge:
Create code that does, in order:
- Takes 8-bit ASCII input from STDIN; e.g
n
(Hex 6E, or Bin 01101110) - Shifts each byte's 8 bits down 1 bit level (I believe it's called a
bitwise shift down), e.g
01101110
becomes00110111
("put my thing down"); - Inverts each byte's bits, e.g
00110111
becomes11001000
("flip it"); - Reverses the bits for each byte, e.g
11001000
becomes00010011
("reverse it"); - If a byte's value is less than 32, then perform
(95 + [byte value])
, or in other words,(126-(31-[byte value]))
, on the byte before converting back to ASCII... If the byte value is still less than 32, repeat step 5 - If a byte's value is greater than 126, then perform
([byte value] - 95)
, or in other words,(32+([byte value]-127))
, on the byte before converting back to ASCII... IF the value is still greater than 126, repeat step 6. - Display the newly converted string as ASCII.
An example of this code in action:
(The input, is it worth it?)
workit missy
("missy" being the input, "workit" is the function)
Now behind the scenes...
(let me work it... Into binary)
01101101 01101001 01110011 01110011 01111001
(Put my thing down... Bitwise)
00110110 00110100 00111001 00111001 00111100
(...Flip it...)
11001001 11001011 11000110 11000110 11000011
(... And reverse it!)
10010011 11010011 01100011 01100011 11000011
(Converted back to Decimal)
147 211 99 99 195
(Perform the necessary math)
147-95 211-95 99 99 195-95 => 52 116 99 99 100
(Convert back to ASCII and display, the output)
4tccd
Rules
- Shortest code wins... simple as that...
- Input can be via function, by prompt or whatever works for you, so long as you can make Rule 1 "work it" for you... ;)
- I am not after reversibility, so long as you can make the code do what I have asked it to do, I'll be happy...
Best of luck!
0 1 1 0 1 1 0 1
and0 1 1 0 1 0 0 1
formi
\$\endgroup\$P
turns into the byte value235
and subtracting95
leaves you with140
. Still unprintable. Or do I misunderstand? \$\endgroup\$