Skip to content

FromDigits ​

The integer a digit string denotes, in any numeral system. The inverse of IntegerDigits — and the round trip is the whole specification of a system.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageFromDigits!
FromDigits([d1, d2, …])integer formed from a digit list in base 10.
FromDigits(string, base?)integer formed from a digit string, 0-9 then a-z.
FromDigits([d1, d2, …], base)integer formed from a digit list in the given base.
FromDigits(digits, system)read the digits in that system
FromDigits(roman, "Roman")the integer a Roman numeral spells, the inverse of RomanNumeral.
FromDigits(digits, x)a symbolic base gives the polynomial the digits spell in x.
FromDigits(digits, negativeBase)a negative base reads with the same Horner reduction as a positive one.
FromDigits({digits, exponent})reads the single {digits, exponent} pair RealDigits itself returns, base 10.
Typed signatures
TypePackageApplies
(collection<any>, integer?) -> integercompute-enginealways
(collection<any>, any?) -> integernumeralsreplaces compute-enginealways

Domain: Numeral systems

Details
  • A digit string that denotes NO integer leaves the call standing: two adjacent Zeckendorf ones, an out-of-range mixed-radix digit, residues that no integer satisfies
  • In a residue system with moduli that are not pairwise coprime the map is not a bijection, and an inconsistent string has no value
  • Zeckendorf is the clearest case of a system whose digits are constrained by a forbidden PATTERN rather than a per-place bound
  • Reading a ResidueNumerals numeral IS the Chinese remainder theorem: the digits are the ResidueClass classes of nn, and ChineseRemainder of those classes gives it back
  • In a fixed base, the inverse of IntegerDigits: FromDigits(IntegerDigits(n))=n\mathrm{FromDigits}(\mathrm{IntegerDigits}(n))=n for n≥0n\ge0.
  • Digits need not be restricted to 0..base−10..\mathrm{base}-1 -- a digit ≥\ge base simply carries into higher place values.
  • An empty digit list has no natural value; compute-engine leaves it unevaluated rather than returning 0.
  • compute-engine's FromDigits takes a list of digits, not a digit string.

Examples

14 more kept as data, checked against the oracles
Basic #
live ↗
InFromDigits([5,1,2,8])\mathrm{FromDigits}(\bigl\lbrack5, 1, 2, 8\bigr\rbrack)Out5 1285\,128
live ↗
InFromDigits([1,0,1,1,0,1,1],2)\mathrm{FromDigits}(\bigl\lbrack1, 0, 1, 1, 0, 1, 1\bigr\rbrack, 2)Out9191

1d 2h 3m 4s back to seconds

live ↗
InFromDigits([1,2,3,4],MixedRadixNumerals([24,60,60]))\mathrm{FromDigits}(\bigl\lbrack1, 2, 3, 4\bigr\rbrack, \mathrm{MixedRadixNumerals}(\bigl\lbrack24, 60, 60\bigr\rbrack))Out93 78493\,784

CRT reconstruction

live ↗
InFromDigits([2,3,2],ResidueNumerals([3,5,7]))\mathrm{FromDigits}(\bigl\lbrack2, 3, 2\bigr\rbrack, \mathrm{ResidueNumerals}(\bigl\lbrack3, 5, 7\bigr\rbrack))Out2323

1 day 4 h 25 min 41 s converted to seconds

live ↗
InFromDigits([1,4,25,41],MixedRadixNumerals([24,60,60]))\mathrm{FromDigits}(\bigl\lbrack1, 4, 25, 41\bigr\rbrack, \mathrm{MixedRadixNumerals}(\bigl\lbrack24, 60, 60\bigr\rbrack))Out102 341102\,341
Scope #

The digits can be given as a string, 0-9 then a-z

live ↗
InFromDigits(1923)\mathrm{FromDigits}(\text{1923})Out1 9231\,923

a digit string in a given base

live ↗
InFromDigits(1011011,2)\mathrm{FromDigits}(\text{1011011}, 2)Out9191

Roman numerals, with the base "Roman"

live ↗
InFromDigits(XVII,Roman)\mathrm{FromDigits}(\text{XVII}, \text{Roman})Out1717

a mixed radix, spelled MixedRadix: 1d 4h 25m 41s back to seconds

live ↗
InFromDigits([1,4,25,41],MixedRadix([24,60,60]))\mathrm{FromDigits}(\bigl\lbrack1, 4, 25, 41\bigr\rbrack, \mathrm{MixedRadix}(\bigl\lbrack24, 60, 60\bigr\rbrack))Out102 341102\,341

the inverse of IntegerDigits(137, MixedRadix([3, 12]))

live ↗
InFromDigits([3,2,5],MixedRadix([3,12]))\mathrm{FromDigits}(\bigl\lbrack3, 2, 5\bigr\rbrack, \mathrm{MixedRadix}(\bigl\lbrack3, 12\bigr\rbrack))Out137137

digits past 9 are plain integers: 1⋅16+151 \cdot 16 + 15

live ↗
InFromDigits([1,15],16)\mathrm{FromDigits}(\bigl\lbrack1, 15\bigr\rbrack, 16)Out3131

a symbolic base gives the polynomial x2+2x+3x^2 + 2x + 3

live ↗
InFromDigits([1,2,3],x)\mathrm{FromDigits}(\bigl\lbrack1, 2, 3\bigr\rbrack, x)Outx2+2x+3x^2+2x+3

a negative base: 1⋅4−1⋅2+0=21 \cdot 4 - 1 \cdot 2 + 0 = 2

live ↗
InFromDigits([1,1,0],−2)\mathrm{FromDigits}(\bigl\lbrack1, 1, 0\bigr\rbrack, -2)Out22

a {digits, exponent} pair — the shape RealDigits gives — reads as 1.4151.415

live ↗
InFromDigits([[1,4,1,5],1])\mathrm{FromDigits}(\bigl\lbrack\bigl\lbrack1, 4, 1, 5\bigr\rbrack, 1\bigr\rbrack)Out283200\frac{283}{200}

ordinary base 2 as a system value

live ↗
InFromDigits([1,0,0,0,0,1,1,0,0,0,1,1],PositionalNumerals(2))\mathrm{FromDigits}(\bigl\lbrack1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1\bigr\rbrack, \mathrm{PositionalNumerals}(2))Out2 1472\,147

Place weights 36,12,136,12,1 from radices [3,12][3,12]: 3⋅36+2⋅12+53\cdot36+2\cdot12+5

live ↗
InFromDigits([3,2,5],MixedRadixNumerals([3,12]))\mathrm{FromDigits}(\bigl\lbrack3, 2, 5\bigr\rbrack, \mathrm{MixedRadixNumerals}(\bigl\lbrack3, 12\bigr\rbrack))Out137137
Applications #

a Lehmer code back to its rank

live ↗
InFromDigits([0,2,1,0],FactorialNumerals)\mathrm{FromDigits}(\bigl\lbrack0, 2, 1, 0\bigr\rbrack, \mathrm{FactorialNumerals})Out55
Properties #

FromDigits inverts IntegerDigits

live ↗
InFromDigits(IntegerDigits(58 127))=58 127\mathrm{FromDigits}(\mathrm{IntegerDigits}(58\,127))=58\,127OutTrue\mathrm{True}

the round trip holds in any base

live ↗
InFromDigits(IntegerDigits(58 127,2),2)\mathrm{FromDigits}(\mathrm{IntegerDigits}(58\,127, 2), 2)Out58 12758\,127

Days-hours-minutes-seconds again, inverse of IntegerDigits

live ↗
InFromDigits([1,3,22,14],MixedRadixNumerals([24,60,60]))\mathrm{FromDigits}(\bigl\lbrack1, 3, 22, 14\bigr\rbrack, \mathrm{MixedRadixNumerals}(\bigl\lbrack24, 60, 60\bigr\rbrack))Out98 53498\,534
Possible issues #

An empty digit list is left unevaluated rather than treated as 0

live ↗
InFromDigits([])\mathrm{FromDigits}(\bigl\lbrack\bigr\rbrack)OutFromDigits([])\mathrm{FromDigits}(\bigl\lbrack\bigr\rbrack)

two adjacent ones is not a numeral, so it denotes nothing

live ↗
InFromDigits([1,1],ZeckendorfNumerals)\mathrm{FromDigits}(\bigl\lbrack1, 1\bigr\rbrack, \mathrm{ZeckendorfNumerals})OutFromDigits([1,1],ZeckendorfNumerals)\mathrm{FromDigits}(\bigl\lbrack1, 1\bigr\rbrack, \mathrm{ZeckendorfNumerals})
live ↗
InMap(FromDigits,[7,8,9,"A",B,"C",D])\mathrm{Map}(\mathrm{FromDigits}, \bigl\lbrack\text{7}, \text{8}, \text{9}, "A", \text{B}, "C", \text{D}\bigr\rbrack)Out[7,8,9,10,11,12,13]\bigl\lbrack7, 8, 9, 10, 11, 12, 13\bigr\rbrack
Neat examples #

Digits ≥ the base carry into higher place values: 7×105+11×104+122=8101227\times10^5+11\times10^4+122=810122

live ↗
InFromDigits([7,11,0,0,0,122])\mathrm{FromDigits}(\bigl\lbrack7, 11, 0, 0, 0, 122\bigr\rbrack)Out810 122810\,122
About
Examples38
Checked againstWolfram Language 25 agree2 differ
CrosswalkWolfram Language

See also: IntegerDigits, NumeralSystemShape, ChineseRemainder