Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to convert a number into base 2 and then use IntegerDigits[] on it.

When using BaseForm[i,2], the notebook only displays the output in a wrapper, but does not actually convert the number into a base 2 sequence.

This causes problems when I want to use IntegerDigits[] on the base 2 number to get a list of the binary digits, e.g. {1,0,0,1,1}. It simply displays IntegerDigits[10011 2]. How could I solve this?

Thank you

share|improve this question

closed as off-topic by Michael E2, Szabolcs, rasher, m_goldberg, Yves Klett Mar 10 '14 at 7:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, Szabolcs, rasher, m_goldberg, Yves Klett
If this question can be reworded to fit the rules in the help center, please edit the question.

It doesn't make sense to "convert" a number to binary, only displaying it as binary. The base is not a property of the number, it is a property of the representation of the number. What IntegerDigits does is precisely obtain a representation. You just need IntegerDigits[something, 2]. –  Szabolcs Mar 10 '14 at 2:28

2 Answers 2

As noted by Szablocs and rasher, the easiest way to do what is being asked is to use IntegerDigits directly.

IntegerDigits[19, 2]
{1, 0, 0, 1, 1}
share|improve this answer

Got it.

Although it is a bit involved, I used IntegerDigits[ToExpression[IntegerString[19, 2]]].

This gives me the exact answer that I want, i.e. {1,0,0,1,1}.

share|improve this answer
Why not just use IntegerDigits[19, 2]? –  rasher Mar 10 '14 at 2:05
Because I'm nowhere near as clever as you... Thanks! –  Aron Mar 10 '14 at 23:52

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