0
$\begingroup$

Does Mathematica have a build in way to convert a list of numbers into a list of binary numbers? If not how can this be accomplished?

$\endgroup$
2
  • $\begingroup$ There's BaseForm and IntegerDigits. $\endgroup$
    – wxffles
    Commented Feb 22, 2015 at 19:21
  • $\begingroup$ I think you should explain more clearly what exactly you mean with "list of binary numbers". You probably want to explain what you want to do with such a list... $\endgroup$ Commented Feb 22, 2015 at 20:04

1 Answer 1

4
$\begingroup$
list = RandomInteger[{0, 100}, 10]

{65, 84, 31, 23, 72, 64, 29, 78, 43, 87}

BaseForm[#, 2] & /@ list

enter image description here

IntegerDigits[#, 2] & /@ list

{{1, 0, 0, 0, 0, 0, 1}, {1, 0, 1, 0, 1, 0, 0}, {1, 1, 1, 1, 1}, {1, 0, 1, 1, 1}, {1, 0, 0, 1, 0, 0, 0}, {1, 0, 0, 0, 0, 0, 0}, {1, 1, 1, 0, 1}, {1, 0, 0, 1, 1, 1, 0}, {1, 0, 1, 0, 1, 1}, {1, 0, 1, 0, 1, 1, 1}}

FromDigits /@ %

{1000001, 1010100, 11111, 10111, 1001000, 1000000, 11101, 1001110, \ 101011, 1010111}

$\endgroup$
2
  • 2
    $\begingroup$ BaseForm and IntegerDigits are both listable. $\endgroup$
    – Karsten7
    Commented Feb 22, 2015 at 21:40
  • $\begingroup$ @Karsten7. - Good point. $\endgroup$
    – Bob Hanlon
    Commented Feb 23, 2015 at 1:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.