String to Binary
Python 3, 41 bytes
print(*[bin(ord(x))[2:]for x in input()])
Like KSFT's answer, but I thought I'd point out that, in addition to raw_input -> input
, Python 3 also has an advantage here due to the splat for print
.
CJam, 8 bytes
l:i2fbS*
Easy-peasy:
l:i "Read the input line and convert each character to its ASCII value";
2fb "Put 2 on stack and use that to convert each ASCII value to base 2";
S* "Join the binary numbers by space";
Try it here
Pyth, 10 bytes
jdmjkjCd2z
Python mapping and explanation:
j # join( "Join by space"
d # d, "this space"
m # Pmap(lambda d: "Map characters of input string"
j # join( "Join by empty string"
k # k, "this empty string"
j # join( "This is not a join, but a base conversion"
C # Pchr( "Convert the character to ASCII"
d # d "this character"
# ),
2 # 2 "Convert to base 2"
# )
# ),
z # z))) "mapping over the input string"
Input is the string that needs to be converted without the quotes.
Try it here