Tag Info

Hot answers tagged


It should be possible to use notation of the form base^^number inside the BaseForm expression like this: BaseForm[2^^10101,14] There are some similar examples under Properties and Relations in the documentation for BaseForm.


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 ...


You can see that the base never survives to the evaluation stage by trying for example 16^^98 // Unevaluated // AtomQ True 16^^98 // Unevaluated // Head Integer Trace[16^^98, TraceInternal -> True] {} It's more or less like a box formatting rule. The Front End sends the literal structure to the kernel, it first builds up the ...


The reason is that the notation base^^digits is interpreted at parsing time, not evaluation time. I explained the difference in this answer. You can use FromDigits instead: fromBaseTwo = FromDigits[#, 2]& fromBaseTwo["10011"] Note that I used a string as input. FromDigits works both with strings and lists of digits.


No, AFAIK there is no way to see the FullForm and I think your conclusion is correct. The ^^ is not an operator, it is a form how you can input a number. Effectively, this behavior applies to all form of numerical input. For instance this is unholdable too HoldComplete[16*^2] (* HoldComplete[1600] *) Advanced expanation To give a more thorough ...


Here are the above elements wrapped up in function which pulls together the various, or user defined, output forms and lets you switch from any base to any base: Clear[BaseTranslator]; Options[BaseTranslator] = {BTForm -> BaseForm}; BaseTranslator[number_, base1_, base2_, OptionsPattern[]] := (OptionValue@BTForm)[ FromDigits[ToString[number], ...


Since numbers given in base^^ form automatically parse as regular number, it can be at times useful to pass numbers around as strings. For example: FromDigits["100010011110011", 2] 17651 Different ways to represent that number: IntegerDigits[17651, 16] BaseForm[17651, 2] IntegerString[17651, 2] {4, 4, 15, 3} 1000100111100112 ...


Don't use BaseForm[number,base] Use IntegerDigits[number,base] : IntegerDigits[10, 2] (* ---> {1, 0, 1, 0} *) It returns a List of Integers, which is a very good thing for further processing


What is important here is to distinguish between data and representation. When you input an integer, you actually input a representation of the integer. That is, even without specifying the base, you don't enter the integer 42 (you would be hard-pressed to do that), but the decimal representation of the integer, consisting of the two digits 4 and 2, in that ...


Incedentally it is NumberForm, not PaddedForm you want to right pad with zeros: This works, though you are left with the 16 subscripts.. NumberForm[BaseForm[Grid[Partition[Map[FromDigits[#, 16] &, RealDigits[FractionalPart[CubeRoot[Table[Prime[n], {n, 64}]]], 16, 8, -1][[All, 1]]], 8], Alignment -> Right], 16], 8, ...


Here is a somewhat messed-up way to do something like what you wanted to do: ToExpression["2^^" <> ToString[#]] & /@ {1000, 1101} {8, 13}


This answer is due to ssch. Instead of using BaseForm, use of IntegerString generates the correct output: Grid[Partition[ Map[IntegerString[FromDigits[#, 16], 16, 8] &, RealDigits[FractionalPart[CubeRoot[Table[Prime[n], {n, 64}]]], 16, 8, -1][[All, 1]]], 8], Alignment -> Right] results in:


You could do something like this: toBaseString[n_?NumericQ, b_Integer?Positive] := First @ StringSplit @ ToString @ BaseForm[n, b] toBaseString[365.7, 5] "2430.32222" I missed that you didn't want strings. Perhaps you want this?: toBasePlain[n_?NumericQ, b_Integer] /; 11 > b > 0 := N @ FromDigits @ RealDigits[n, b] toBasePlain[365.7, ...

Only top voted, non community-wiki answers of a minimum length are eligible