It looks to me like a number in a base other than base 10 gets evaluated before the evaluator ever gets a chance to be tweaked.
For example, FullForm[16^^abcdef] or even FullForm[HoldAll[16^^abcdef]] both produce 11259375.
Am I missing a trick that would get me some sort of less evaluated form? I guess I can use BaseForm[] when I need to record what base the number originally was in.
Answer
To understand what's happening, the difference between evaluation and parsing needs to be made clear:
parsing means taking the string (the text) input to Mathematica and converting it to some internal representation of a Mathematica expression
evaluation means taking a Mathematica expression and transforming it according to some rules the evaluator knows about
The string 16^^abcdef gets directly parsed into an Integer. 11259375 gets parsed to the very same integer. The way Mathematica stores integers internally does not include the base in which the number was originally. 16^^abcdef and 11259375 are two ways to write the exact same Mathematica expression.
The information about the base is lost at parse time, the evaluator never sees it.
If you read 16^abcdef as input interactively or from a file, you need to make sure you read it as a string (e.g. InputString) and avoid parsing it into a Mathematica expression. Then you can analyse the string an find out what is the base.
Comments
Post a Comment