| Bytes | Lang | Time | Link |
|---|---|---|---|
| 021 | JavaScript | 230228T001121Z | noodle p |
| 036 | Casio BASIC fx9750giii | 240910T133256Z | madeforl |
| 036 | TIBASIC | 240918T195535Z | absolute |
| 002 | Uiua | 240208T070826Z | Adelie |
| 114 | Acc!! | 240420T051741Z | DLosc |
| 072 | YASEPL | 240207T135545Z | madeforl |
| 028 | Swift | 230723T231403Z | macOSist |
| 014 | *><> | 240215T143757Z | Bee H. |
| 029 | Labyrinth | 240214T073738Z | Bubbler |
| 013 | Perl 5 | 240207T150227Z | Xcali |
| 001 | Japt | 230227T154049Z | noodle p |
| 025 | ForWhile | 230724T170736Z | bsoelch |
| 013 | Zsh | 230724T135744Z | roblogic |
| 027 | Befunge93 | 230614T230429Z | TotallyJ |
| 001 | Thunno 2 | 230614T172106Z | The Thon |
| 001 | vemf | 230402T041139Z | mí |
| 040 | BrainFlak | 230402T034225Z | Wheat Wi |
| 008 | Raku | 230313T020448Z | Mark Ree |
| 068 | Scratch | 230227T235124Z | noodle p |
| 355 | Minecraft Data Pack via Lectern | 230312T180919Z | Command |
| 026 | Prolog SWI | 230228T072946Z | Aiden Ch |
| nan | Piet + asciipiet | 230307T065747Z | Bubbler |
| 002 | J | 230303T180526Z | Richard |
| 029 | Knight v2 | 230303T091958Z | Aiden Ch |
| nan | Piet + asciipiet | 230228T021541Z | Aiden Ch |
| 017 | Simply | 230301T205438Z | Ismael M |
| 002 | CJam | 230301T201510Z | emirps |
| 009 | R | 230301T131501Z | pajonk |
| 001 | Jelly | 230301T045958Z | Aiden Ch |
| 025 | Alice | 230301T034240Z | Julian |
| 020 | Swift | 230227T222455Z | user1171 |
| 070 | SNOBOL4 CSNOBOL4 | 230301T023405Z | Giuseppe |
| 003 | Charcoal | 230227T084053Z | Neil |
| 037 | Pure Bash no external utilities | 230227T182851Z | Digital |
| 062 | Haskell | 230228T215358Z | DLosc |
| 078 | Quipu | 230228T202408Z | DLosc |
| nan | Piet + asciipiet | 230227T145027Z | Parcly T |
| 001 | APLDyalog Extended | 230228T080244Z | Aiden Ch |
| 006 | PARI/GP | 230228T100719Z | alephalp |
| 001 | flax | 230228T095959Z | zoomlogo |
| 006 | PHP | 230228T095203Z | Kaddath |
| 031 | Haskell | 230228T093923Z | Aiden Ch |
| 023 | GeoGebra | 230228T073441Z | Aiden Ch |
| 028 | Befunge93 PyFunge | 230228T053621Z | yeah ok |
| 050 | Desmos | 230228T000727Z | Aiden Ch |
| 002 | J | 230227T230426Z | south |
| 003 | Pip | 230227T204744Z | jezza_99 |
| 016 | Scala | 230227T202116Z | waf9000 |
| 011 | Excel | 230227T195019Z | Engineer |
| 004 | dc | 230227T173851Z | Digital |
| 003 | Julia 0.7 | 230227T151304Z | Kirill L |
| 001 | MATL | 230227T150358Z | Suever |
| 008 | Ruby n | 230227T150248Z | Kirill L |
| 024 | C# .NET Core | 230227T140145Z | Tvde1 |
| 054 | Python 2 | 230227T113132Z | ElPedro |
| 015 | Arturo | 230227T132823Z | chunes |
| 004 | Factor | 230227T132543Z | chunes |
| 015 | Risky | 230227T124212Z | xigoi |
| 045 | Nim | 230227T124943Z | xigoi |
| 015 | Nibbles | 230227T123827Z | xigoi |
| 001 | Pyt | 230227T112610Z | Kip the |
| 023 | Retina 0.8.2 | 230227T100149Z | Neil |
| 001 | Brachylog | 230227T095256Z | Fatalize |
| 070 | Whitespace | 230227T082857Z | Kevin Cr |
| 018 | Wolfram Language Mathematica | 230227T083011Z | ZaMoC |
| 132 | BrainFlak | 230227T073139Z | RaviRavi |
| 018 | Java 8 | 230227T075601Z | Kevin Cr |
| 001 | MathGolf | 230227T075329Z | Kevin Cr |
| 021 | C GCC | 230227T074854Z | badatgol |
| 014 | bc | 230227T055628Z | cocomac |
| 001 | 05AB1E | 230227T072004Z | The Thon |
| 001 | Vyxal | 230227T071706Z | The Thon |
| nan | 230227T071536Z | The Thon | |
| 002 | K ngn/k | 230227T071456Z | doug |
| 013 | Python | 230227T063208Z | loopy wa |
| 017 | Python | 230227T055451Z | Parcly T |
| 016 | JavaScript | 230227T053440Z | Unmitiga |
| 019 | Python 3 | 230227T044952Z | SectorCo |
JavaScript, 21 bytes
f=n=>n?f(n>>1)+n%2:""
Not quite as short as the builtin but wanted to get a short solution doing it more manually. This solution recursively divides n by 2 and prepends the remainder.
Explanation:
f = n => // define f with arg n
n // is n nonzero?
? // yes ->
f( // recurse with
n >> 1 // equivalent to floor dividing by 2
) + n % 2 // append remainder (0 or 1)
: "" // no -> empty string is prepended to coerce everything
Figured this out from reading wikiHow to convert decimal to binary lol
Casio BASIC (fx-9750giii), 40 38 36 bytes
(this is a translation of absoluteAquarian's answer in TI-BASIC. rock on, you're cool!)
?→A
2^-Seq(X,X,Int (ln A÷ln 2),0,-1)A
MOD(Intg List Ans,2
asks you for a number, then prints it out as binary in the form of a list.
Casio BASIC (fx-9750giii), 6 bytes(?)
this requires the calculator to be in decimal mode and it has to be typed in mathprint.
?→A:A▶Bin
TI-BASIC, 36 bytes
Prompt A
iPart(ln(A+.5)/ln(2
2fPart(.5int(A2^(cumSum(binomcdf(Ans,0))-Ans-1
A modified/fixed version of a routine on the wiki (1) to support only base 2.
Explanation:
Prompt A ; Request the number
; A = 18
iPart(ln(A+.5)/ln(2 ; Get how many digits the number has in binary - 1
; Ans = 4
cumSum(binomcdf(Ans,0))-Ans-1 ; Make a list from -Ans to 0
; = [ -4, -3, -2, -1, 0 ]
2^ ; Convert to powers of 2
; = [ .0625, .125, .25, .5, 0 ]
int(A ; Convert to even and odd numbers
; = [ 1, 2, 4, 9, 18 ]
2fPart(.5 ; Convert to modulus 2
; Ans = [ 1, 0, 0, 1, 0 ]
; Implicit print of Ans
Examples:
prgmCDGF2C
A=?15
{1 1 1 1}
prgmCDGF2C
A=?16
{1 0 0 0 0}
prgmCDGF2C
A=?18
{1 0 0 1 0}
Note: TI-BASIC is a tokenized language. Character count does not equal byte count.
Program size is equal to \$MEM\: byte\: count - program\: name\: length - 9\: bytes\$.
Uiua, 9 2 bytes
-7 bytes since the challenge doesn't disallow functions
⇌⋯
Returns an array of bits. Try it online!
Explanation
⋯ # encode number as bit array, LSB-first
⇌ # reverse array
Acc!!, 114 bytes
Count i while _%11-10 {
_*10+_%11+N%48
}
_/11
Count d while 1 {
Count i while 1/(_/2^d) {
Write 48+_/2^(d-i)%2
}
}
Outputs nothing when the input is 0. Exits with an error. Try it online!
Explanation
# Read a decimal integer
# We'll store the value in _/11 and the most recently read digit (or 10 for newline)
# in _%11
# Loop until the most recently read character was a newline
Count i while _%11-10 {
# (_-_%11)*10 Multiply the value by 10
# +(_%11)*11 Add the most recent digit to the value
# +N%48 Read the next digit or newline
# This gives (_-_%11)*10+(_%11)*11+N%48
# which simplifies to _*10-(_%11)*10+(_%11)*11+N%48
# which simplifies to...
_*10+_%11+N%48
}
# Store the value in the accumulator directly
_/11
# Write the accumulator value as base 2
# Figure out how many bits the accumulator value has
Count d while 1 {
# The i loop only runs once 2^d is the same bit length as the accumulator
# value, at which point it outputs all the bits and then throws an error,
# ending the program
# This happens when _/2^d is 1, i.e. 1/(_/2^d) is not zero
# If the accumulator value is 0, the loop condition instead throws a division-by-zero
# error, ending the program with no output
Count i while 1/(_/2^d) {
# Output each bit from most significant to least significant
Write 48+_/2^(d-i)%2
# When d-i becomes negative, the expression is a float, and Write throws
# an error because Python's chr() doesn't accept a float argument
}
}
If outputting little-endian is allowed, we can get this down to 80 bytes:
Count i while _%11-10 {
_*10+_%11+N%48
}
_/11
Count d while _ {
Write 48+_%2
_/2
YASEPL, 76 72 bytes
=d'(=1)""`9!m$d%!1ſm!d/(}7,0,9=o-!h)""!u®1-=k$u`8!m¥u,1!hſm!u-}1,o,8>h
YASEPL is a (horribly coded and just stupid in general) esolang I made a while ago in Node.JS. it gets input via a prompt and STDIN. heres the output:
Swift, 35 28 bytes
let b={String($0+0,radix:2)}
*><>, 14 bytes
Input is passed in through the -i flag.
:2%:n-2,:0)?!;
: Duplicate the value on the stack
2 Push 2 onto the stack
% Modulo those two
: Duplicate the result
n Pop and print that duplicate
- Subtract the result from our original number
2 Push 2
, Divide the two
: Duplicate that result
0 Push 0
)?!; If the dividend is greater than 0, loop again
Labyrinth, 29 bytes
?
~:"" 2%!@
_ ( _ "
2/);(""
Handling zero input is nontrivial since loops in Labyrinth require a nonzero value at entry. To remedy this, the code uses bitwise NOT of the input value and repeatedly divides it by 2, which is floor division and therefore equivalent to arithmetic right shift. The loop is exited when the top reaches -1, and it runs at least once to ensure that the second loop is also entered with a nonzero value. As a result, the input of 0 outputs 0.
Entry ?~
? Take input [n]
~ Bitwise NOT [~n]
Loop 1 :_2/)( [~n ~n/2 .. ~n/2^i] -> [~n .. ~n/2^(i+1)]
:_2/ Copy and divide by 2
) Test if the top is -1; exit if so
( Revert the value to continue the loop
Path ; [~n ~n/2 .. ~n/2^i 0] -> [~n ~n/2 .. ~n/2^i]
; Drop the unnecessary zero
Loop 2 (_2%! [~n ~n/2 .. ~n/2^i] -> [~n .. ~n/2^(i-1)]
( Invert the parity of the top
(decrement is chosen to ensure the top is nonzero)
_2%! Mod 2 and print
Exit the loop if there is nothing more to print
End @
@ Halt
ForWhile, 25 bytes
{:[:1&'2/0@1+0$:)@[48+#)}
Takes argument from the stack and prints to console
Explanation
{ } \ anonymous procedure
:[ \ repeat n times
:1& \ push the lowest bit of n
'2/ \ divide n by 2
0@1+0$ \ increment memory cell 0
:) \ break loop if n is zero
@ \ read memory at address 0 (n is still on stack)
[48+#) \ print bits converted to characters
Befunge-93, 27 Bytes
v
2:._@#<-
&
<_!#: ^#/2\%2:
Alternately the following works as long as 0/0 results in a non-zero value pushed onto the stack (this is an option of PyFunge and the default behavior of this compiler online
v
2:._@#<-
&
<_ :/^#2\%2:
This results in only needing 26 bytes
This is my first post and so if anyone has comments of how I can improve this post feel free to let me know
Brain-Flak, 40 bytes
{(<>)<>({<({}[()])><>[(()[{}])]()<>})}<>
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.
{(<>)<>({<({}[()])><>[(()[{}])]()<>})}<>
Raku, 8 bytes
.base(2)
The above version operates on the current topic, as seen in the demo code. To make it a function accepting an argument, just wrap it in curly braces for another two bytes.
Scratch, 70 68 bytes
Puts a list of binary digits onto the a global variable, which is automatically displayed when the program finishes execution.
Saved 2 bytes by using ([floor v]of((n)/(2 instead of ((n)-(((n)mod(2))/(2
Scratchblocks syntax:
define a(n
if<(n)>(0)>then
a([floor v]of((n)/(2
add((n)mod(2))to[a v
Minecraft Data Pack via 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).
Prolog (SWI), 26 bytes
:-read(X),format("~2r",X).
With builtin.
Prolog (SWI), 42 36 35 bytes
-6 bytes thanks to @Steffan
-1 byte thanks to @false
N+X:-N<1,X=0;N//2+B,X is N/\1+10*B.
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!
Piet + ascii-piet, 29 bytes (6×9=54 codels)
tkvuumf_iliqqdltT QqKln?_sf ?
B2C2 is I (no-op). The printing loop is now:
O d 1 % D I
which nicely forms a color loop.
Piet + ascii-piet, 33 bytes (5×9=45 codels)
tkvuumf_iliqqdltT _?tser?_iqtf? ?
The bit-extracting logic is the same as Parcly Taxel's. 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
J 2 bytes
#:
Some test cases:
#:12345
1 1 0 0 0 0 0 0 1 1 1 0 0 1
#:33
1 0 0 0 0 1
Knight (v2), 29 bytes
;=a@;=n*2P;W=n/n 2=a+,%n 2aOa
Zero outputs nothing, which is allowed in the rules.
Piet + ascii-piet, 50 44 42 bytes (2×25=50 2×22=44 2×21=42 codels)
tabru?qd?t?itknmdjem_ a?liqdltailckt?iq ?
Pointer Path
Simply, 17 bytes
The code simply creates an anonymous arrow function that calls the &tb function, and returns the result.
fn($x)=>&tb($x 2)
To use this function, assign it to a variable and call it:
$fn = fn($x)=>&tb($x 2)
echo call $fn(5);
What does &tb do?
The function &tb is a built-in alias to &tobase.
This is the result of running echo &doc(&tobase);:
Documentation for tobase:
Converts the integer $number to the $base.
The $base must be between 1 and 36, otherwise, returns null.
E.g.: tobase(10, 10) = "10", tobase(10, 2) = "1010", tobase(10, 1) = "1111111111".
Ungolfed
You can rewrite the code like this:
Set the variable $fn to an anonymous function with the argument $number.
Begin.
Return the result of calling the function &tobase with the arguments $number and 2;
End.
Or, if you want it to be more code-like:
$fn = anonymous function($number) {
return &tobase($number, 2);
};
CJam, 2 bytes
Yb
Link includes test cases
Explanation
b # Convert to base
Y # builtin *2*
For fun, here's one which pads to 16 bits:
CJam, 6 bytes
YbGTe[
Explanation
b # Convert to base
Y # builtin *2*
e[ # and pad to length
G # builtin *16*
# with
T # zeroes
R, 9 bytes
intToBits
Outputs as little-endian with trailing zeros.
R, 18 bytes
\(n)n%/%2^(n:0)%%2
Outputs as big-endian (standard convention) with possibly a lot of leading zeros.
Alice, 25 bytes
/O \v$.:2[!<
@Mq/>.2%'0+^
This explanation below are still valid, I just reorganised the flow to save two bytes
/ M \w.2%'0+![2:.$K/ q O @ Full program (includes a new line)
/ M \ Reads the argument
w .$K Main loop
.2% Gets the modulus by two of the number
'0+![ Store the modulus + the char code of 0 to the tape
2: Divide the number by 2
/ q O @ Join the tape, output and exit
Swift, 55 49 20 bytes
-6 bytes thanks to @RydwolfPrograms
-29 bytes thanks to @Jacob
{String($0,radix:2)}
SNOBOL4 (CSNOBOL4), 70 bytes
I =INPUT
N O =REMDR(I,2) O GT(I) :F(O)
I =I / 2 :(N)
O OUTPUT =O
END
Charcoal, 3 bytes
⍘N²
Try it online! Link is to verbose version of code. Explanation:
N Input as a number
⍘ Convert to base as a string
² Literal integer `2`
Implicitly print
16 bytes without base conversion builtins:
P0NθWθ«←§01θ≧÷²θ
Try it online! Link is to verbose version of code. Explanation:
P0
Output 0 by default (not strictly necessary according to the question definition but the builtin version does this).
Nθ
Input the integer.
Wθ«
Repeat until it is zero.
←§01θ
Output the least significant bit of the integer, moving right-to-left. (←I﹪θ² would also work for the same byte count.)
≧÷²θ
Integer divide the integer by 2.
Pure Bash (no external utilities), 37
b()(((a=$1/2))&&b $a
echo -n $[$1%2])
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 ))
}
Haskell, 62 bytes
import Data.Sequence
d 0=Nothing
d n=Just$divMod n 2
unfoldl d
A different approach than Aiden Chow's answer; 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)
Quipu, 78 bytes
2&1@0&2&0&3&
//**[][][][]
1&2&2&++1&/\
>>>>%% --
\/1&1& 0&
[] >>
**
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
Haskell, 31 bytes
f 0=0
f n=n`mod`2+10*f(n`div`2)
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.
Befunge-93 (PyFunge), 28 bytes
2&v
2/>:0`!#^_:2%\
._@#-2:<
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.
Desmos, 50 bytes
f(n)=mod(floor(n/2^{[floor(log_2(n+0^n))...0]}),2)
Scala, 16 bytes
_.toBinaryString
Try it Online! I took some inspiration from the Java solution's boilerplate to hide the type inference elsewhere.
Excel, 11 bytes
=BASE(A1,2)
Straightforward built-in. Input is in the cell A1 and can be anything from 0 to 253-1. Formula goes in any other cell in the sheet.
Python 2, 62 54 bytes
i,o=input(),""
while i:i,j=divmod(i,2);o=`j`+o
print o
Just as a way of doing it without any builtins.
Retina 0.8.2, 23 bytes
.+
$*
+`(1+)\1
$+0
01
1
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 $+.
Whitespace, 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 (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.
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.
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
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.
Java 8, 18 bytes
n->n.toString(n,2)
Explanation:
n-> // Method with Integer parameter and String return-type
n.toString(n,2) // Convert and return the given Integer as base-2 String
MathGolf, 1 byte
à
Explanation:
à # Convert the (implicit) input-integer to a binary-string
# (after which the entire stack is output implicitly as result)
Irrelevant note: â (convert to a binary-list) isn't an equal-byte alternative, since it (for whatever reason) outputs in reversed order.
C (GCC), 21 bytes
f(n){printf("%b",n);}
Will be pretty shocked if there is any way to do it shorter in C (unless I missed a weird print function).
bc - 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.
Python 3, 19 bytes
lambda n:bin(n)[2:]


