[Question]
  [
This is a code golf challenge. Just like the title says, write a program to covert a string of ascii characters into binary. 
For example:
`"Hello World!"`
should turn into 
`1001000 1100101 1101100 1101100 1101111 100000 1010111 1101111 1110010 1101100 1100100 100001`.
Note: I am particularly interested in a pyth implementation.
  
[Answer]
# Python 3, 41 bytes
```
print(*[bin(ord(x))[2:]for x in input()])
```
Like [KSFT's answer](https://codegolf.stackexchange.com/a/44831/21487), 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`.
[Answer]
# 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](http://cjam.aditsu.net/)
[Answer]
# 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](http://pyth.herokuapp.com/)
[Answer]
# [MITS Altair 8800](https://en.wikipedia.org/wiki/Altair_8800), 0 bytes
Input string is at memory address `#0000H` ([allowed](https://codegolf.meta.stackexchange.com/a/8510/84624)). Output in binary via front panel I/O lights `D7-D0`.
Example, do `RESET`, then `EXAMINE` to see the first byte, followed by repeating `EXAMINE NEXT` to see the rest.
`"H" = 01 001 000:`
[![enter image description here](https://i.stack.imgur.com/yT3W2.png)](https://i.stack.imgur.com/yT3W2.png)
`"e" = 01 100 101:`
[![enter image description here](https://i.stack.imgur.com/FNuAN.png)](https://i.stack.imgur.com/FNuAN.png)
`"l" = 01 101 100:`
[![enter image description here](https://i.stack.imgur.com/iSryY.jpg)](https://i.stack.imgur.com/iSryY.jpg)
[Try it online!](https://s2js.com/altair/sim.html)
Non-competing, of course. :)
[Answer]
# Python 3 - 43 bytes
---
```
print(*map("{:b}".format,input().encode()))
```
No quite the shortest, but an interesting approach IMO. It has the added advantage that if the number of significant bits varies, E.G. `Hi!`, padding with zeros is trivial (2 more bytes, as opposed to 9 for `.zfill(8)`):
```
print(*map("{:08b}".format,input().encode()))
```
[Answer]
# Python - 52
```
print" ".join([bin(ord(i))[2:]for i in raw_input()])
```
~~I'll work on translating this into Pyth.~~ Someone else did a Pyth answer already.
If you don't care about it being a full program or about I/O format and use Python 3, you can do it in 23 bytes like this:
```
[bin(ord(i))for i in x]
```
`x` is the input.
I know this doesn't count because the interpreter wasn't released before the challenge was posted, but here it is in KSFTgolf:
```
oan
```
[Answer]
# Ruby, ~~34~~ ~~28~~ 24 bytes
```
$<.bytes{|c|$><<"%b "%c}
```
Takes input via STDIN. 6 bytes saved thanks for AShelly and another 4 thanks to britishtea.
[Answer]
# PowerShell, ~~63~~ ~~59~~ 46 bytes
-13 bytes thanks to @mazzy
```
"$($args|% t*y|%{[Convert]::ToString(+$_,2)})"
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/X0lFQyWxKL24RlWhRKuyRrU62jk/ryy1qCTWyiokP7ikKDMvXUNbJV7HSLNWU@k/UIMHUF@@jkJ4flFOiqISAA "PowerShell – Try It Online")
[Answer]
# [Forth (gforth)](http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/), 45 bytes
```
: f 0 do dup i + c@ 2 base ! . decimal loop ;
```
[Try it online!](https://tio.run/##FcVBDkAwEEDRq/zaChFLNpZuYI1paTIyjXL@ird5we7nbI7wV8pAoEMMeRORmn2iZ1uzx9Eifo/XqqhZYiy5YvaqxmK3iqsI5QM "Forth (gforth) – Try It Online")
### Code Explanation
```
: f           \ start a new word definition
  0 do        \ start a loop from 0 to string length - 1
    dup i +   \ duplicate the address and add the loop index to get addr of current character
    c@        \ get the character at that address
    2 base !  \ set the base to binary
    .         \ print the ascii value (in binary)
    decimal   \ set the base back to decimal
  loop        \ end the loop
;             \ end the word definition
```
[Answer]
# Matlab
This is an anonymous function
```
f=@(x) dec2bin(char(x))
```
usage is `f('Hello World')`.
Alternatively, if `x` is defined as the string `Hello World!` in the workspace, then just `dec2bin(char(x))` will work.
[Answer]
# J - 9
```
1":#:3&u:
```
No idea how to make this in a row without doubling the length of the code, I need J gurus to tell me :)
```
1":#:3&u:'Hello world!'
1001000
1100101
1101100
1101100
1101111
0100000
1110111
1101111
1110010
1101100
1100100
0100001
```
[Answer]
# Java - 148 Bytes
```
public class sToB{public static void main(String[] a){for(int i=0;i<a[0].length();i++){System.out.print(Integer.toString(a[0].charAt(i) ,2)+" ");}}}
```
Edited to include full file
[Answer]
# JavaScript ES6, 63 65 bytes
```
alert([for(c of prompt())c.charCodeAt().toString(2)].join(' '))
```
This is rather long, thanks to JavaScript's long function names. The Stack Snippet below is the rough ES5 equivalent, so it can be run in any browser. Thanks to edc65 for the golfing improvements.
```
alert(prompt().split('').map(function(e){return e.charCodeAt().toString(2)}).join(' '))
```
[Answer]
# Scala - 59 - 55 Bytes
```
readLine().map(x=>print(x.toByte.toInt.toBinaryString))
```
Normally, one should use foreach and not map.
[Answer]
# [Python 3.6](https://docs.python.org/3.6/), 39 bytes
```
print(*[f'{ord(c):b}'for c in input()])
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzv6AoM69EQys6Tb06vyhFI1nTKqlWPS2/SCFZITMPiApKSzQ0YzX///dIzcnJVwjPL8pJUQQA "Python 3 – Try It Online")
[Answer]
# Ruby, 24 bytes
I was hoping to beat [Martin Ender](https://codegolf.stackexchange.com/a/44836/11261), but I only managed to tie him.
Takes input on STDIN; +1 bytes for `-p` flag.
```
gsub(/./){"%b "%$&.ord}
```
[Try it online!](https://tio.run/##KypNqvz/P724NElDX09fs1pJNUlBSVVFTS@/KKX2/3@P1JycfIXw/KKcFMV/@QUlmfl5xf91CwA "Ruby – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 39 bytes
```
print(*[f'{ord(i):b}'for i in input()])
```
[Try it online!](https://tio.run/##K6gsycjPM/7/v6AoM69EQys6Tb06vyhFI1PTKqlWPS2/SCFTITMPiApKSzQ0YzX///dIzcnJVwjPL8pJUQQA "Python 3 – Try It Online")
Slight improvement over the [current leading Python answer](https://codegolf.stackexchange.com/a/44846/87681)
[Answer]
# x86-16 machine code, IBM PC DOS, ~~33~~ ~~31~~ 28 bytes
**Binary:**
```
00000000: d1ee ad8a c849 b308 ac92 b000 d0e2 1430  .....I.........0
00000010: cd29 4b75 f5b0 20cd 29e2 ebc3            .)Ku.. .)...
```
**Listing:**
```
D1 EE       SHR  SI, 1          ; point SI to DOS PSP (80H) 
AD          LODSW               ; load input string length into AL, SI to 82H  
8A C8       MOV  CL, AL         ; set up loop counter 
49          DEC  CX             ; remove leading space/slash from char count 
        LOOP_CHAR: 
B3 08       MOV  BL, 8          ; loop 8 bits 
AC          LODSB               ; load next char 
92          XCHG AX, DX         ; use DX for bit shift 
        LOOP_BIT: 
B0 00       MOV  AL, 0          ; clear AL 
D0 E2       SHL  DL, 1          ; high-order bit into CF 
14 30       ADC  AL, '0'        ; AL = '0' + CF              
CD 29       INT  29H            ; write AL to screen 
4B          DEC  BX             ; decrement bit counter 
75 F5       JNZ  LOOP_BIT       ; loop next bit              
B0 20       MOV  AL, ' '        ; display a space 
CD 29       INT  29H            ; write AL to screen 
E2 EB       LOOP LOOP_CHAR      ; loop next char 
C3          RET                 ; return to DOS
```
A standalone PC DOS executable COM file. Input is via command line, output to screen.
[![enter image description here](https://i.stack.imgur.com/sgSUD.png)](https://i.stack.imgur.com/sgSUD.png)
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `S`, 3 bytes
```
bƛṅ
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=S&code=b%C6%9B%E1%B9%85&inputs=Hello%2C%20World!&header=&footer=)
Explanation:
```
b    # Convert each letter to a list of bits
 ƛ   # In each list of bits:
  ṅ  #   Join elements
     # 'S' flag - join top of stack with spaces and output
```
[Answer]
# [Rust](https://www.rust-lang.org/), 47 45 bytes
```
|s:&str|for i in s.bytes(){print!("{:b} ",i)}
```
[Try it online!](https://tio.run/##PY2xCoMwGIRn8xR/MpQI0gdQOnWwU7dSSumg9Q8E0vySRKFonj1NHVzuu@MOzk0@JGXh02kry4UZDKBOafX1wQe3KnKgQVvwx/4b0OfJ6LQNXIql7iOISpcxNWzfzfjmT3FBYwju5MzARSXONCC0ZFT2V5zRZbZkbfennjHjQVPW2yheCyv2iwj1dtGwQskNW2UslzlEFtMP "Rust – Try It Online")
A closure iterating over the string, converting each character to its ascii number, then printing out it's binary equivalent with `:b`
Turns out you don't need `{}` always to define a closure
[Answer]
# Haskell, 65
```
m s=tail$do c<-s;' ':do j<-[6,5..0];show$mod(fromEnum c`div`2^j)2
```
heavy use of the list monad. it couldn't be converted to list comprehentions because the last statements weren't a `return`.
[Answer]
# C++ - 119 bytes
Freeing memory? What's that?
```
#include<cstdio>
#include<cstdlib>
int main(int c,char**v){for(*v=new char[9];c=*(v[1]++);printf("%s ",itoa(c,*v,2)));}
```
(MSVC compiles the code with warning)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes
```
OBK
```
[Try it online!](https://tio.run/##y0rNyan8/9/fyfv////qHkBevo5CeH5RToqiOgA "Jelly – Try It Online")
[Answer]
# [Tcl](http://tcl.tk/), 52 bytes
```
proc B s {binary s $s B* b;regsub -all .{8} $b {& }}
```
[Try it online!](https://tio.run/##K0nO@f@/oCg/WcFJoVihOikzL7GoEshSKVZw0lJIsi5KTS8uTVLQTczJUdCrtqhVUElSqFZTqK39X1BaUqwQ7aSg5JGak5OvUJ5flJOiqBT7/z@UDwA "Tcl – Try It Online")
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 12 bytes
```
10⊥2⊥⍣¯1⎕UCS
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT////1FH26O2CYYGj7qWGgHxo97Fh9YbPuqbGuocDJZUUPdIzcnJ11EIzy/KSVFUBwA "APL (Dyalog Unicode) – Try It Online")
Thanks to [Adám](https://codegolf.stackexchange.com/users/43319/ad%C3%A1m) for help with this solution.
[Answer]
# Commodore VIC-20/C64/128 and TheC64Mini, 101 tokenized BASIC bytes
Here is the obfuscated listing using Commodore BASIC keyword abbreviations:
```
 0dEfnb(x)=sG(xaNb):inputa$:fOi=1tolen(a$):b=64:c$=mI(a$,i,1):fOj=0to6
 1?rI(str$(fnb(aS(c$))),1);:b=b/2:nEj:?" ";:nE
```
Here for explanation purposes is the non-obfuscated symbolic listing:
```
 0 def fn b(x)=sgn(x and b)
 1 input a$
 2 for i=1 to len(a$)
 3 let b=64
 4 let c$=mid$(a$,i,1)
 5 for j=0 to 6
 6 print right$(str$(fn b(asc(c$))),1);
 7 let b=b/2
 8 next j
 9 print " ";
10 next i
```
The function `fn b` declared on line zero accepts a numeric parameter of `x` which is `AND`ed with the value of `b`; [SGN](https://www.c64-wiki.com/wiki/SGN) is then used to convert `x and b` to `1` or `0`.
Line one accept a string input to the variable `a$`, and the loop starts (denoted with `i`) to the length of that input. `b` represents each bit from the 6th to 0th bit. `c$` takes each character of the string at position `i`.
line 5 starts the loop to test each bit position; `right$` is used in line 6 to remove a auto-formatting issue when Commodore BASIC displays a number, converting the output of `fn b` to a string; `asc(c$)` converts the current character to its ascii code as a decimal value.
Line 7 represents the next bit value. The loop `j` is ended before printing a space, then the last loop `i` is ended.
[![C64 converting PETSCII to Binary](https://i.stack.imgur.com/4hBi7.png)](https://i.stack.imgur.com/4hBi7.png)
[Answer]
# JavaScript ES6, 71 bytes
```
alert(prompt().split('').map(c=>c.charCodeAt(0).toString(2))).join(' ')
```
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 34 bytes
```
i\~48*o
?\:0(?;:2%:}-2,:0=
?\{nl1=
```
[Try it online!](https://tio.run/##S8sszvj/PzOmzsRCK5/LPsbKQMPe2spI1apW10jHysAWKFSdl2No@/@/R2pOTr5CeH5RTooiAA "><> – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 4 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Çbðý
```
[Try it online.](https://tio.run/##yy9OTMpM/f//cHvS4Q2H9/7/75Gak5OvEJ5flJOiCAA)
**Explanation:**
```
Ç     # Convert the (implicit) input-string to a list of unicode values
 b    # Convert each integer to a binary string
  ðý  # Join by spaces (and output the result implicitly)
```
Could be just the first two bytes if a list output is allowed, or 3 bytes with `»` if a newline delimiter instead of space delimiter is allowed.
[Answer]
# [Perl 5](https://www.perl.org/), 21 bytes
```
printf'%b ',ord for@F
```
[Try it online!](https://tio.run/##K0gtyjH9/7@gKDOvJE1dNUlBXSe/KEUhLb/Iwe3//0SFJIVkhRSFVIW0f/kFJZn5ecX/dd0A "Perl 5 – Try It Online")
]