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

Mathematica won't change a number's BaseForm recursively:

63969 // BaseForm[#, 16] & // BaseForm[#, 8] & // BaseForm[#, 2] &

Well, I inspected former answers, most of them treated formatting problems, but none of the anwers given treated the nestable aspect. Maybe I'm wrong, and I risk a duplicate.

(1) I would like to have a nestable function which allows constructs of the form

63969 // base@16 // base@8 // base@2

This feature might be adopted advantageously within iterative functions : NestList, FoldList, ...


To explain my interest for seamless changes of baseforms

2 ArcCot[GoldenRatio^2^^1111] == ArcCot[2^^1010101010]
2^^1010101010 // BaseForm[#, 4] &



I tried myself another approch, but it has an disadvantage: HoldForm isn't respected

base[b_] := Function[# // ReplaceAll[#, BaseForm[x_, _] :> BaseForm[x, 10]] & // 
     ToString // ToExpression // BaseForm[#, b] &]

testsuite = {5555, BaseForm[5555, 8], HoldForm@Plus[5000, 555],5*BaseForm[1111, 2]}
base@10 /@ testsuite
share|improve this question

You can define your own function that works with input the BaseForm of a number, sure:

myBase[a_?NumericQ, base_Integer] := BaseForm[a, base];
myBase[a_BaseForm, base_Integer] :=
    IntegerString @@ a,

so that

63969 // myBase[#, 16] & // myBase[#, 8] &

gives you BaseForm[63969,8] but using as input the number's representation in hexadecimal.

share|improve this answer
I often change the base of a number. Let's say I stored the number already in variable x. Now I don't want to remember if it's stored as a BaseForm or not. It shouldn't be important at all. Just using x//base@2, and that's it – hieron Aug 20 '14 at 15:42
thanks - so then it is just an issue of defining a function that works on BaseForm. What I didn't understand why you'd want to go through the process of jumping from base to base but if it is on potentially stored numbers it makes sense. – gpap Aug 20 '14 at 15:46
base = If[Head[#] === BaseForm, BaseForm[First @ #, #2], BaseForm[##]] &;
FoldList[base, 63696, {16, 8, 2}]

enter image description here

share|improve this answer

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.