r/dailyprogrammer • u/rya11111 3 1 • Mar 15 '12
[3/15/2012] Challenge #25 [intermediate]
Write a program to do the following:
input: a base ten (non-fractional) number at the command line
output: the binary representation of that number.
12
Upvotes
7
u/prophile Mar 15 '12
Done in Python.
5
u/Cosmologicon 2 3 Mar 15 '12
bc:
3
u/luxgladius 0 0 Mar 15 '12 edited Mar 15 '12
Perl one-liner:
1100100
3
u/mattryan Mar 15 '12
Java:
2
u/CarNiBore Mar 16 '12
JavaScript
1
u/SleepyTurtle Mar 15 '12
python: shortest method i could come up with
i'm not sure how to remove the 0b tag from the output. i suppose i could delete it from the string, but there is probably a more elegant solution.
1
u/robin-gvx 0 2 Mar 15 '12
Déjà Vu: http://www.hastebin.com/raw/gadeyofifu
Chokes on negative input(*), prints the empty string on zero. No named arguments or variables.
(*) It originally was
while > 0 dup:, but I changed it towhile dup:because it looked prettier. It's also slightly faster, but who cares about that?1
u/Yuushi Mar 16 '12
C99:
This may not be portable, however, as right-shifting signed numbers is implementation defined. Using gcc -std=gnu99 is fine, though.
1
u/devilsassassin Jun 22 '12
Because everyone did it the easy way: