# Tag Info

18

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.

18

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

15

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

12

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.

11

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

10

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], base1],...

8

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

7

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

5

Here is another way to generate ternary number strings of a certain length. ternaryStrings[len_Integer?Positive] := StringJoin @@@ Map[ToString, Tuples[{0, 1, 2}, len], {2}] With this ternaryStrings[1] {"0", "1", "2"} ternaryStrings[2] {"00", "01", "02", "10", "11", "12", "20", "21", "22"} ternaryStrings[3] {"000", "001", "002", "...

4

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

4

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

4

n = 3; list = Tuples[{0, 1, 2}, n]; To get numbers rather than lists of digits: list2 = FromDigits /@ list (* {0, 1, 2, 10, 11, 12, 20, 21, 22, 100, 101, 102, 110, 111, 112, 120, 121, \ 122, 200, 201, 202, 210, 211, 212, 220, 221, 222} *) Or BaseForm[#, 3] & /@ Range[0, 3^n - 1] To pad with leading 0's IntegerString[#, 3, n] & /@ Range[...

3

This may seem counter-intuitive, but what works is to rationalize the number first, Rationalize[523.502] (* 261751/500 *) This allows us to take advantage of the following property of RealDigits For integers and rational numbers with terminating digit expansions, RealDigits[x] returns an ordinary list of digits. Combining the two then will give you ...

2

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

2

Here is a better solution than your workwaround : FromDigits[#, 2] & /@ {"0", "11", "10", "0"} or : FromDigits[#, 2] & /@ ToString /@ {0, 11, 10, 0} {0, 3, 2, 0}

2

This should get you closer BaseExponent[ a_. Power[b_, e_]] := ({a^(1/e) b, e} /. {a2_. Power[b2_, e2_], e3_} :> {a2^(1/e2) b2, e3*e2}) BaseExponent[a_Integer] := {a, 1} BaseExponent[a_Rational] := {a, 1} BaseExponent[a_. Complex[r_, i_]] := {a Complex[r, i], 1} (* EDIT: added per evansdoe comment *) And @@ { BaseExponent[(1 + I Sqrt[3])...

2

It appears the maximum base is constrained by the computer's available memory. For example, i = 10000!; Table[IntegerLength[i, 2^b], {b, 1, 2^16}] works (note the maximum base used here is $2^{2^{16}}$, or $2^{65536}$), but i = 10000!; Table[IntegerLength[i, 2^b], {b, 1, 2^32}] doesn't, and produces an error: General::nomem: The current computation ...

1

FromDigits can do the job: FromDigits["1000000000000101", Range[2, 10]] (* {32773, 14348917, 1073741841, 30517578151, 470184984613, 4747561509993, 35184372088897, 205891132094731, 1000000000000101} *)

1

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:

1

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, 5]...

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