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.

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 at 18:14

3 Answers 3

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

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

(*
1111101
7d
*
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] 
"10220"  
FromDigits[ToExpression@Characters[%], 3]
105
share|improve this answer
    
@Kuba: can you point me to a FAQ where I can learn the standards of prefered layout? –  Wouter Apr 3 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 at 19:09

Your Answer

 
discard

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.