Ruby -p
, 50 bytes
gsub(/./){"%07b"%$&.ord}
gsub(/./){$`=~/#$&$/?0:1}
Explanation
First line, same as Value Ink's answerValue Ink's answer:
gsub(/./){ $& } # Replace each character $&…
.ord # …with its ASCII code…
% # …formatted as…
"%07b" # …binary digits padded to 7 places.
Second line:
gsub(/./){ $& } # Replace each character $&…
$` # …if the text to its left…
=~ # …matches…
/# $/ # …the Regexp /c$/ where "c" is the character…
?0:1 # …with 0, or 1 otherwise.
In Ruby you can use interpolation in Regexp literals, e.g. /Hello #{name}/
, but withand for variables that start with $
or @
you can omit the curly braces, so if e.g. $&
is "0"
then the grawlixy /#$&$/
becomes /0$/
.