[Question]
  [
It seems we've managed to go all this time without a plain vanilla Number-To-Binary challenge! Whilst this will inevitably be only one element in many languages, it should put a few esolangs through their paces.
I truly looked for this challenge to no avail. If it already exists, comment as such and I'll delete this post-haste.
# Input
A single non-negative integer.
# Output
The same number as represented in Base 2.
# Test Cases
* `4 -> 100`
* `10 -> 1010`
* `1234 -> 10011010010`
# Victory Condition
[code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so fewest bytes wins!
# Notes
* The output must consist of digits `0` and `1`, either as characters or individual numbers in a list.
* Zero may optionally return nothing.
* [Standard IO Applies](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods)
* [Standard Loopholes Apply](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default)
* Have Fun!
  
[Answer]
# [Piet](https://www.dangermouse.net/esoteric/piet.html) + [ascii-piet](https://github.com/dloscutoff/ascii-piet), 29 bytes (6√ó9=54 codels)
```
tkvuumf_iliqqdltT QqKln?_sf ?
```
[Try Piet online!](https://piet.bubbler.one/#eJxtjcEOgzAIht-F898EbHW2r1I9LK5LTFxn0u1k9u5D504KBPj5CCw0PG-JQowMD0GtLgKxkBbie0RhNNDk1KXSnsHr2K_aH0OZw8n8hxpctsvtEdntqz9hPaikmQIZYwg0jQ_thdVUpTJQuF-nkkBjnt-vlVXWdVm3u8x7_WvZq6_p8wWwszr1)
![](https://piet.bubbler.one/api.svg?6,9,0,9,1,5,5,11,13,18,19,10,6,10,4,4,12,6,0,0,19,4,19,19,19,19,19,19,19,4,9,19,19,19,19,19,19,19,6,7,18,18,19,19,19,19,19,3,13,19,18,19,19,19,19,19)
B2C2 is `I` (no-op). The printing loop is now:
```
O d 1 % D I
```
which nicely forms a color loop.
---
# [Piet](https://www.dangermouse.net/esoteric/piet.html) + [ascii-piet](https://github.com/dloscutoff/ascii-piet), 33 bytes (5√ó9=45 codels)
```
tkvuumf_iliqqdltT _?tser?_iqtf? ?
```
[Try Piet online!](https://piet.bubbler.one/#eJxlTEEOwjAM-0vOrpR0G7T9SrcDGkWaNMqkwmni76Qw2IEkSuzY8krj7ZwoxMjwEHTaIpAG4iB-QBTGAbpabbGKGVzf_uP4nyo6dWnEEfbtcrtSg_iXv0sDqKSFAhljCDRPV8XCWspSGSlcTnNJoCkvj3vVbNP2Wd195u1-uWzXd_R8AR7-NQs)
![](https://piet.bubbler.one/api.svg?5,9,0,9,1,5,5,11,13,18,19,10,6,10,4,4,12,6,0,0,19,18,19,19,19,19,19,19,19,18,0,3,17,2,18,18,19,19,10,4,0,13,18,19,18,19,19)
The bit-extracting logic is the same as [Parcly Taxel's](https://codegolf.stackexchange.com/a/258456/78410). The printing logic is new.
Loop 1: push bits of the input (`A1 -> A8 -> B8 -> B1 -> A1`)
```
D           No-op
I           Take input (n); no-op afterwards
d 2 %       [...bits n n%2]
2 1 r 2 /   [...bits n%2 n/2]
d ! D       Turn right if the new n is 0
```
Now there is a leading zero, which is handled nicely by `A2->B2` (`>`). Since the number below is 0 or 1, and `0>0 == 0` and `1>0 == 1`, the net effect is to simply remove the extra zero.
Loop 2: print bits until the stack is empty (`D2 -> E2 -> E1 -> D2 -> D5 -> E4 -> E1`)
```
d 1 > !    If the top exists, push 1; otherwise push 0
D          Turn right if it is 1; halt otherwise (white trap)
O          Output as number
```
[Answer]
# [Python](https://www.python.org), 13 bytes
```
"{:b}".format
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhZrlaqtkmqV9NLyi3ITSyBiNxULijLzSjS0NNI0KjQVgFIKFQqZeQpFiXnpqRqGBpqamhCFCxZAaAA)
[Answer]
# [Piet](https://www.dangermouse.net/esoteric/piet.html) + [ascii-piet](https://github.com/dloscutoff/ascii-piet), 73 bytes (7√ó12=84 codels)
```
um    R metabrujjL    ?  ll?dD    j  d ?T    l rr tN   ttbj nfI        nn
```
[Try Piet online!](https://piet.bubbler.one/#eJxtjsEOgjAQRP9lz9OkW0oL_RXCwWBNSFBJqifDv7sFFEXbSbqTeTvpg7rrMVJomhLM4HqT-XJct2jyK5CHBjuwFaZEJddt-VvVOricipE-s2NeCJt1Q__2uOUvM6Hhd4DOK3YpkqwA_6n4lJ8rMtOCUhwpkFKKQEN_lpm1HHExdRROhyFFUH8Z77ecmcLS9ATEoUJ-)
![](https://i.stack.imgur.com/VBTu5.png)
[Answer]
# [Piet](https://www.dangermouse.net/esoteric/piet.html) + [ascii-piet](https://github.com/dloscutoff/ascii-piet), ~~50~~ ~~44~~ 42 bytes (~~2√ó25=50~~ ~~2√ó22=44~~ 2√ó21=42 codels)
```
tabru?qd?t?itknmdjem_  a?liqdltailckt?iq ?
```
[Try Piet online!](https://piet.bubbler.one/#eJw9jNEKgzAMRf8lz7fQdLWr_RXtw3AdCM4J3Z5k_75E6UJIbk5ustP0uhdKw2DBAezh0IEjPNhpt1rYSu9xBbNiAaeMGQP30AzqC-o8LgPOf1ZZJ7ftjz_cMWdQLRslMsYQaJmfotlKyFTqROlxW2oBzev2ecvOj6tYx5VtE-7S2B_R9wfDfzDK)
### Pointer Path
[![](https://i.stack.imgur.com/N9PTk.png)](https://i.stack.imgur.com/N9PTk.png)
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 132 bytes
```
{(({})<><(()())>)({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]{})<>({}<(()())>)({}(<>))<>([()]{()<(({})){({}[()])<>}{}>}{}<><{}{}>)}<>
```
Outputs the individual numbers in a list with newlines as separators, and does not output anything for 0.
Explanation:
```
{                                                                   #  loop while top of left stack is not 0
(({})<><(()())>)({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]{})<>    #  leave the result of modulo 2 on right stack
({}<(()())>)({}(<>))<>([()]{()<(({})){({}[()])<>}{}>}{}<><{}{}>)    #  integer division by 2 on left stack
}                                                                   #  end loop
<>                                                                  #  switch to right stack
                                                                    #  implicit output of active (right) stack
```
[Try it online!](https://tio.run/##bYwxDoAwDAO/Yw@ssET5SNWhDEgIxMAa9e3FLWulKHLsnPe3nM9y3OVqLYCoNDeAIJ06YU5Zf8TQTmCWU6NqzJH0xDxApRMWnQjQZh0@Siy6pFRr2/oB "Brain-Flak ‚Äì Try It Online")
I'm not the best at this language so I may have left a lot of room for further golfing, please let me know if you found a better way to do it.
[Answer]
# [Thunno](https://github.com/Thunno/Thunno), \$ 1\log\_{256}(96)\approx \$ 0.82 bytes
```
b
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuhYLkyA0lLtgkaEBhAUA)
[Answer]
# Pure [Bash](https://www.gnu.org/software/bash/) (no external utilities), 37
```
b()(((a=$1/2))&&b $a
echo -n $[$1%2])
```
[Try it online!](https://tio.run/##NYtBCoAgEADv@4o9WOghSvMWvSQ6rLlgEAoZ9HyzoLnNwDjKoRQnlZSSZqF7o1TbOhQEvIWEXUSxCN2YVZU77AfjyeTx4nxtlHlCnwAr9fjb5@8MPkUuFvQA2owWHg "Bash ‚Äì Try It Online")
This is a recursive function `b()` that takes its argument and divides by 2. If the result is non-zero, then `b()` is recursively called with the result. After the recursive call, the remainder when the argument is divided by 2 is the current binary digit. This is a pretty standard base conversion by repeated division by 2, with remainders becoming digits in base 2. Making it a recursive function has a couple of advantages here:
* Recursive function boilerplate is marginally shorter than while loop boilerplate for the same algorithm
* The repeated division yields digits (remainders) in reverse order to how they should be presented. By outputting the digit at each level after the recursive call, we effectively use the call stack to store the yielded digits and replay them back in the correct order
Ungolfed and perhaps a bit more readable:
```
function b() {
    a=$(( $1 / 2 ))
    if (( $a != 0 )); then
        b $a
    fi
    echo -n $(( $1 % 2 ))
}
```
[Answer]
# JavaScript, 16 bytes
```
x=>x.toString(2)
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNEts/ifZvu/wtauQq8kP7ikKDMvXcNI838BkFGikaZhoqnJBWMbGmhq/gcA)
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 2 bytes
```
2\
```
[Try it online!](https://ngn.codeberg.page/k#eJxLszKK4eLS5zLhMjTgMjQyNuECcq1CrBI8VYzjNWpiLI1stazUNeMNrBISi9LLFAy5uNLUQ7gAO34MFQ==)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 1 byte
```
b
```
[Try it online!](https://tio.run/##yy9OTMpM/f8/6f9/QwMA "05AB1E ‚Äì Try It Online")
[Answer]
## [bc](https://man.archlinux.org/man/extra/bc/bc.1.en) - 14 bytes
```
obase=2;read()
```
Run bc by typing `bc` into a terminal and pressing `Enter`. Type this code in, press `Enter`, type in the number to convert, and finally press `Enter` one more time. Press `Ctrl` + `C` to exit `bc`.
`read()` reads user input (in base 10 by default), and then `obase=2` sets it to output in binary. Given that we don't tell it to do any math operations (other than base-conversion), it just outputs the input, but in binary due to the `obase=2`.
Example:
```
$ bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
obase=2;read()    <-- Press Enter
1234              <-- Press Enter again
10011010010       <-- Press Ctrl + C to exit
^C
(interrupt) Exiting bc.
```
I've tested this on Arch Linux, but any system with `bc` installed should work.
[Answer]
# [C (GCC)](https://gcc.gnu.org), 21 bytes
```
f(n){printf("%b",n);}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700OT49OXnBgqWlJWm6FlvTNPI0qwuKMvNK0jSUVJOUdPI0rWshcjddgaIKuYmZeRqaXNVcnGkaJprWCgWlJcUaSkqa1iABQwMMESNjVFVQw2AWAgA)
Will be pretty shocked if there is any way to do it shorter in C (unless I missed a weird print function).
[Answer]
# [Befunge-93 (PyFunge)](https://pythonhosted.org/PyFunge/), 28 bytes
```
2&v
2/>:0`!#^_:2%\
 ._@#-2:<
```
[Try it online!](https://tio.run/##S0pNK81LT9W1NNYtqAQz//83UivjMtK3szJIUFSOi7cyUo3hUtCLd1DWNbKy@f/f0MjYhAsA "Befunge-93 (PyFunge) ‚Äì Try It Online")
## Explanation:
`2&v` and `>` below: Push 2 (used as an "end of string" character of sorts), push user input (henceforth X), then go down and enter the main loop.
### Main Loop
`:0\`!`: Check if X is greater than 0. Invert the answer. (Specifically: duplicate X, push 0, swap, greater than, invert)
`#^_`: If top of stack is 1 (i.e. X <= 0), go up to print loop, else continue right. (Bridge, (up), horizontal if)
`:2%`: Get X%2. (Duplicate X, push 2, modulo)
`\`: Store below X on stack. (Swap)
`2/`: Divide X by 2. Loop restarts with this as X. (push 2, integer divide)
### Print Loop
`<`: Go left. (going right here would add a `!` but it would not increase bytes as we have a spare whitespace on the left)
`-2:`: Check if top of stack = 2 (end of string). (RTL; duplicate, push 2, subtract)
`_@#`: Terminate program if top of stack = 0 (i.e. next item is 2). (RTL; bridge, (terminate), horizontal if)
`.`: Print top of stack as integer.
Note: I originally had a `$` to pop the leading 0 above the `^` in the main loop, but as per comments, leading 0s are allowed. Changing the `^` to a `v` would be equivalent, unless I were to add back in the `$` at the cost of 6 vs 10 bytes.
[Answer]
# [Haskell](https://www.haskell.org/), 31 bytes
```
f 0=0
f n=n`mod`2+10*f(n`div`2)
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P03BwNaAK00hzzYvITc/JcFI29BAK00jLyElsyzBSPN/bmJmnoKtQko@V0FRZl6JgopCmoIJEtvQAJljZGzyHwA "Haskell ‚Äì Try It Online")
I'm unsure why `f$n`div`2` doesn't work as opposed to `f(n`div`2)`... I hope someone can explain this to me and help golf this code.
[Answer]
# [Quipu](https://github.com/cgccuser/quipu), 78 bytes
```
2&1@0&2&0&3&
//**[][][][]
1&2&2&++1&/\
>>>>%%  --
\/1&1&  0&
    []  >>
    **
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m720sDSzoHTBgqWlJWm6Fjf9jNQMHQzUjNQM1IzVuPT1tbSiYyGQyxAoaqSmrW2oph_DZQcEqqoKCrq6XDH6hmqGagoKBmpcCkAQHaugYGcHZmppQUyFGr5giaGRsQmEDQA)
### Explanation
Programs in Quipu consist of several "threads," vertical strips of code that are executed one at a time and also store values. Quipu is missing a lot of features that would have been useful for this challenge: lists, string concatenation, exponentiation... Lacking better methods, we generate the output as a base-10 number whose digits are either 0 or 1.
The first time thread 0 is executed, it loads the input number; subsequently, it divides its value by 2:
```
    # Previous value of this thread (implicit; initially 0)
2&  # Push 2
//  # Divide
1&  # Push 1
>>  # Go to that thread if the above result is greater than 0
\/  # Otherwise, read input number
```
Thread 1 generates successive powers of 10, starting at 1:
```
    # Previous value of this thread
1@  # Push 10
**  # Multiply
2&  # Push 2
>>  # Go to that thread if the above result is greater than 0
1&  # Otherwise, push 1
```
Thread 2 takes the current value mod 2 and multiplies by the appropriate power of 10:
```
0&  # Push 0
[]  # Load that thread's value
2&  # Push 2
%%  # Mod
1&  # Push 1
[]  # Load that thread's value
**  # Multiply
```
Thread 3 keeps a running sum of the values generated by thread 2. This will be our output number.
```
    # Previous value of this thread
2&  # Push 2
[]  # Load that thread's value
++  # Add
```
Thread 4 tests if the value in thread 0 is still greater than 1; if so, jump back to thread 0:
```
0&  # Push 0
[]  # Load that thread's value
1&  # Push 1
--  # Subtract
0&  # Push 0
>>  # Go to that thread if the above result is greater than 0
```
Once thread 0's value has reached 1 (or 0), execution continues with thread 5, which simply outputs the final result:
```
3&  # Push 3
[]  # Load that thread's value
/\  # Print
```
[Answer]
# [Python](https://www.python.org), 17 bytes
```
lambda n:f"{n:b}"
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhYbcxJzk1ISFfKs0pSq86ySapUg4msKijLzSjTSNEyMNDUhQgsWQGgA)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 1 byte
```
b
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJiIiwiIiwiMTAiXQ==)
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 26 bytes
```
:-read(X),format("~2r",X).
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/30q3KDUxRSNCUyctvyg3sURDqc6oSEknQlPv/39DI2MTPQA "Prolog (SWI) ‚Äì Try It Online")
With builtin.
# [Prolog (SWI)](http://www.swi-prolog.org), ~~42~~ ~~36~~ 35 bytes
*-6 bytes thanks to [@Steffan](https://codegolf.stackexchange.com/users/92689/steffan)*
*-1 byte thanks to [@false](https://codegolf.stackexchange.com/users/65772/false)*
```
N+X:-N<1,X=0;N//2+B,X is N/\1+10*B.
```
[Try it online!](https://tio.run/##Dcg9DoMgAAbQqxAnKR8Cav9sS4IHYCaxDC5tTLQQMenm1Wnf@OIa5vDm6TvlbJnruL0ruIe8WSFq1sORKRErnoopeeir3PFljPOUtnIwXuvSMIdXWJdxK4s9Eq7JHvdPgcHAeUoxSCjUaNDiiBPOuOAK9c@6aT2t8g8 "Prolog (SWI) ‚Äì Try It Online")
Without builtin.
---
Man, I haven't golfed in Prolog in a while; I forgot how wonky it is to code in it lol. Please tell me if there are any more golfs!
[Answer]
# [Minecraft Data Pack](https://minecraft.fandom.com/wiki/Data_pack) via [Lectern](https://github.com/mcbeet/lectern), 355 bytes
```
@function a:b
data modify storage  b set value []
scoreboard players set  i 2
function a:c
@function a:c
scoreboard players operation a i = i i
data modify storage  b prepend value 0
execute store result storage  b[0] int 1 run scoreboard players operation a i %=  i
scoreboard players operation i i /=  i
execute if score i i matches 1.. run function a:c
```
The function is `a:b`.
Takes input in the fake player `i` and the objective `i` (Which can be set using `/scoreboard objectives add i dummy`, `/scoreboard players set i i <input number>`).
Outputs a list via data storage `: b` (Which can be read by `/data get storage : b`).
I'm not sure this I/O format is valid, but this would be the standard way to do that if you were writing a library, although with the objective created by the data pack (and, of course, with more meaningful names).
[Answer]
# [Python 2](https://docs.python.org/2/), ~~62~~ 54 bytes
```
i,o=input(),""
while i:i,j=divmod(i,2);o=`j`+o
print o
```
[Try it online!](https://tio.run/##FcxLCoAgEADQ/ZxC2qjloqxV4V0EFZooR8J@p7c6wHvpyTNFXRz5YDjnBRUZjOnIQqqqgmvGNTAcUS3G47mRF6i0nMjYxTYEaceYGZWPQriDE38k674M0LXQ6X54AQ "Python 2 ‚Äì Try It Online")
Just as a way of doing it without any builtins.
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 70 bytes
```
[S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_input_n][N
S S N
_Create_Label_BINARY_LOOP][S N
S _Duplicate_n][N
T   S S N
_If_0_Jump_to_Label_PRINT_LOOP][S N
S _Duplicate_n][S S S T S N
_Push_2][T  S T T   _Modulo][S N
T   _Swap_top_two][S S S T  S N
_Push_2][T  S T S _Integer_divide][N
S N
N
_Jump_to_Label_BINARY_LOOP][N
S S S N
_Create_Label_PRINT_LOOP][T N
S T _Print_as_integer][N
S N
S N
_Jump_to_Label_PRINT_LOOP]
```
Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.  
`[..._some_action]` added as explanation only.
[**Try it online**](https://tio.run/##K8/ILEktLkhMTv3/X0FBgQsIObk4QYALwuPihNBAwAnicIJJGAckxQWS5OIEaQRx//83NDI2AQA) (with raw spaces, tabs and new-lines only).
Outputs with one additional leading `0`. This can be removed at the cost of 8 additional bytes:  
[Try it online](https://tio.run/##K8/ILEktLkhMTv3/X0FBgQsIObk4QYALwuPihNBAwAnicIJJGAckxcUF0QiigXpBBgDluP7/NzQyNgEA).
**Explanation in pseudo-code:**
```
Integer n = STDIN as integer
Start BINARY_LOOP:
  If n==0:
    Jump to PRINT_LOOP
  Push n modulo-2 to the stack
  n = n integer-divided by 2
  Go to the next iteration of BINARY_LOOP
PRINT_LOOP:
  Print current top of the stack as integer to STDOUT
  Go to the next iteration of PRINT_LOOP
```
Stops the program with an error when it tries to print while the stack is empty.
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 1 byte
```
B
```
Try it at [MATL Online](https://matl.io/?code=B&inputs=4&version=22.7.4)
[Answer]
# [Julia 0.7](http://julialang.org/), 3 bytes
```
bin
```
[Try it online!](https://tio.run/##yyrNyUw0/59m@z8pM@@/g55CQVFmXklOnkaaRrSJjqGBjqGRsUmspuZ/AA "Julia 0.7 ‚Äì Try It Online")
# [Julia 1.x](https://julialang.org), 9 bytes
```
bitstring
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700qzQnM3HBojTbpaUlaboWK5MyS4pLijLz0iH8XQ56CgVAbklOnkaaRrSJjqGBjqGRsUmspiZEwYIFEBoA)
Prints with leading zeroes.
[Answer]
# [J](https://www.jsoftware.com), 2 bytes
```
#:
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70wa8FOJT31NAVbKwV1BR0FAwUrINbVU3AO8nFbWlqSpmuxSNkKwtiiyZWanJHvkKZmp2CiYGigYGhkbAKRWrAAQgMA)
`#:` returns the binary expansion of a given number y as a boolean list.
[Answer]
# [Desmos](https://desmos.com/calculator), 50 bytes
```
f(n)=mod(floor(n/2^{[floor(log_2(n+0^n))...0]}),2)
```
[Try It On Desmos!](https://www.desmos.com/calculator/58jgg1jumw)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/ilmjn4qc3o)
[Answer]
# [Haskell](https://www.haskell.org), 62 bytes
```
import Data.Sequence
d 0=Nothing
d n=Just$divMod n 2
unfoldl d
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8GCpaUlaboWNx0ycwvyi0oUXBJLEvWCUwtLU_OSU7lSFAxs_fJLMjLz0oHsPFuv0uISlZTMMt98IE_BiCvJtjQvLT8nJUchBWLO1tzEzDwFW4WCosy8EgUVhSQFQyNjE4gczC4A)
A different approach than [Aiden Chow's answer](https://codegolf.stackexchange.com/a/258528/16766); this one uses `unfoldl` from `Data.Sequence`, which is elegant but unfortunately much less golfy.
### Explanation
`unfold` is conceptually the opposite of `fold`. `fold` takes a function that combines two values into one and a sequence of values, and returns a single value; `unfold` takes a function that splits one value into two and a single value, and returns a sequence of values. Specifically, the type of `unfoldl` looks like this:
```
unfoldl :: (b -> Maybe (b, a)) -> b -> Seq a
```
It takes a function and a single value of type `b` and returns a sequence of values of type `a`. The function must take a value of type `b` and return either a tuple containing one `b` and one `a` or `Nothing`. `unfoldl` applies the function repeatedly to the initial value, taking the first element of the tuple as the new value and saving off the second tuple elements as the sequence. It stops when it gets `Nothing` instead of a tuple.
In our case, both types are `Int`. We want the first element of the tuple to be the input int-divided by 2, and the second element to be the input mod 2. Conveniently, Haskell has a `divMod` function that returns exactly the tuple we want. Thus, our binary converter is just
```
unfoldl d
```
where `d` is a function that stops when it hits `0`:
```
d 0 = Nothing
```
and otherwise returns the result of `divMod` wrapped in a `Maybe`:
```
d n = Just (divMod n 2)
```
[Answer]
# [Swift](https://developer.apple.com/swift/), ~~55~~ ~~49~~ 20 bytes
##### -6 bytes thanks to @RydwolfPrograms
##### -29 bytes thanks to @Jacob
```
{String($0,radix:2)}
```
[Try it online!](https://tio.run/##Ky7PTCsx@V9QlJlXoqHxvzq4BMhK11Ax0ClKTMmssDLSrP2vqWFkrqn5HwA "Swift ‚Äì Try It Online")
[Answer]
# [Brain-Flak](https://github.com/Flakheads/BrainHack), 40 bytes
```
{(<>)<>({<({}[()])><>[(()[{}])]()<>})}<>
```
[Try it online!](https://tio.run/##SypKzMzLSEzO/v@/WsPGTtPGTqPaRqO6NlpDM1bTzsYuWkNDM7q6NlYzVgMoV6tZa2P3//9/Q3MA "Brain-Flak (BrainHack) ‚Äì Try It Online")
The other Brain-flak answer looked very long.
# Explanation
The first thing we can notice is that the following snippet:
```
(()[{}])
```
does something very nice. It's equivalent to `1-x`, which when constrained to the inputs of `0` and `1` will give us an increment and mod 2 operation. So we can calculate the mod 2 of a number by just repeating this snippet that many times starting with `0`.
```
{({}[()])<>(()[{}])<>}
```
This is nice and it can be modified to give us the full `divmod`. Each cycle we add the value of the accumulator we are building. Since it is `1` half the time and `0` the other half this gives us half the value. The one issue is it rounds up instead of down, so instead of adding `n` each step we add `1-n`. That is we add 1 when the accumulator is 0 and 0 when the accumulator is 1.
```
({<({}[()])><>[(()[{}])]()<>})
```
Now we add a bit of code to add a new accumulator each step and we can just repeat this divmod process until the div is zero.
```
{(<>)<>({<({}[()])><>[(()[{}])]()<>})}<>
```
[Answer]
# Java 8, 18 bytes
```
n->n.toString(n,2)
```
[Try it online.](https://tio.run/##LY6xCoMwFEV3v@LhlKCGap0q7d6hLh3FIY1RYvUpJlqK@O02VpcHj3su59Z84kFdvFfRcK3hwRXODoBCI4eSCwnp9gI8zaCwAkHuNqnkAEgTGyyOPdpwowSkgHCFFYMbMtPtBYJ@RNdko/rx1VjqgKdOFdBaG9nBLOd0N5XdQKwe1AXlZxuS5XPshyc/jM7xQv@M3fPVRrasGw3rbd80SJTnXsD1kAmi6LFuWX8)
**Explanation:**
```
n->               // Method with Integer parameter and String return-type
  n.toString(n,2) //  Convert and return the given Integer as base-2 String
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 23 bytes
```
.+
$*
+`(1+)\1
$+0
01
1
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wX0@bS0WLSztBw1BbM8aQS0XbgMvAkMvw/38TLkMDLkMjYxMA "Retina 0.8.2 ‚Äì Try It Online") Link includes test cases. Code is taken from the Retina 0.8.2 unary arithmetic tutorial for decimal to unary and unary to binary, except that for decimal to unary, the input is assumed to be decimal, so `.` is used instead of `\d`, and for unary to binary, `${1}` is golfed to `$+`.
]