Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a simple one-liner to convert a given base 10 integer to a string representation of this integer in some desired base 'b'? Is there a way to do this avoiding the subscript indicating the base, for example the small 2 if we ask for a binary string?

The best thing for my purpose, despite the danger, would be have a function that takes a decimal integer and returns what appears to be the binary, ternary, etc. representation of this integer, but which Mathematica still treats as a decimal integer value.

share|improve this question
closely related – Kuba Apr 3 '14 at 18:14

There's a built-in to do just this, e.g.:

IntegerString[125, 2]
IntegerString[125, 16]

share|improve this answer

I think what you are looking for is a function that, for example takes the number fifteen and the base two, writes 15 in base 2 (which is 1111) and then returns the value one thousand, eleventy one (base 10).

If that's what you're aiming at, then what you are looking for is

f[number_, base_] := FromDigits[IntegerDigits[number, base]]

where base says what the intermediate base you want to filter your number through should be.

In[2]:= f[15, 2]

Out[2]= 1111
share|improve this answer
StringJoin @@ ToString /@ IntegerDigits[105, 3] 
FromDigits[ToExpression@Characters[%], 3]
share|improve this answer
@Kuba: can you point me to a FAQ where I can learn the standards of prefered layout? – Wouter Apr 3 '14 at 19:06
Here's the markdown info. But about "output" there isn't best way. this is the one I'm using :) – Kuba Apr 3 '14 at 19:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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