IntegerDigits
The digits of , most significant first — base 10 by default. The base slot takes a whole numeral SYSTEM, not only an integer — factorial, Zeckendorf, Ostrowski, balanced, negative, bijective, mixed-radix, primorial, combinatorial or residue.
Numerical digitMathWorldDigitWikidataQ82990Wolfram LanguageIntegerDigits!Rosetta CodeSum digits of an integerIntegerDigits(n)digits of in base 10, most significant first.digits(n)[1:]Oscarreverse(digits(BigInt(n)))IntegerDigits(n, base)digits of in the given base.digits(n, base)[1:]Oscarreverse(digits(BigInt(n), base=base))IntegerDigits(n, base, len)the least-significant digits, zero-padded if needed.IntegerDigits(n, system)digits in any of the systems belowdigits(n, system)[1:]Oscarreverse(digits(BigInt(n), base=system))IntegerDigits(n, system, width)left-padded with zeros to width digitsTyped signatures
| Type | Package | Applies |
|---|---|---|
(integer, integer?, integer?) -> list<integer> | compute-engine | always |
(integer, any?, integer?) -> list<integer> | numeralsreplaces compute-engine | always |
Details
- Digits come out most significant first, matching ordinary positional notation.
- In a fixed base the sign of n is discarded, so negative integers give the same digits as their absolute value.
- IntegerDigits(0) is -- there's always at least one digit.
- The 3-argument form keeps only the len least-significant digits, truncating or zero-padding as needed.
- Systems:
PositionalNumerals(b),MixedRadixNumerals([…]),FactorialNumerals,PrimorialNumerals,BalancedNumerals(b),NegativeNumerals(b),BijectiveNumerals(k),ZeckendorfNumerals,OstrowskiNumerals([…]),CombinatorialNumerals(k),ResidueNumerals([…]),AdicNumerals(b, prec?)— also writtenRadix,MixedRadix,Factoradic,PrimorialRadix,BalancedRadix,NegativeRadix,BijectiveRadix,Zeckendorf,Ostrowski,CombinatorialSystem,ResidueSystem PositionalNumerals(b)is ordinary base- notation, — the same digits an integer base already gives, wrapped as a system value so it can stand wherever the others do (NumeralSystemShape, a constant-radixMixedRadixNumeralscomparison)OstrowskiNumerals([a₁, …])is the numeral system a CONTINUED FRACTION defines: place values are the convergents' denominators, and a digit at its ceiling forbids a non-zero digit below it. All quotients 1 is , and that case IS ZeckendorfBalancedNumeralsandNegativeNumeralsrepresent NEGATIVE integers with no sign at all; fixed radix drops the sign instead- The factoradic digits of are the Lehmer code of the -th permutation, so padding to the permutation's size makes the two line up
- An integer with no numeral in a system — anything past in a residue system, say — leaves the call standing rather than answering
- Bijective bases have no zero DIGIT, but zero itself is the empty numeral: that is what makes the correspondence with strings a bijection
- Inverted by FromDigits with the same system
Examples
19 more kept as data, checked against the oraclesScope #
the 10-adic truncation: a negative is spelled by its digits, and the width is part of the numeral
live ↗Applications #
Properties #
Possible issues #
no numeral for a negative in a system that spells only ; the message says which integers it does spell
live ↗About
| Examples | 50 |
|---|---|
| Checked against | Wolfram Language 25 agree1 differSymPy 12 agree1 errorOscar 8 agree |
| Crosswalk | WikipediaMathWorldWikidataWolfram LanguageSymPy ×2Oscar ×2Rosetta Code |
Implementation
oscarpackages/oracle/src/mappings.tsoscarpackages/oracle/src/mappings.tssympypackages/oracle/src/mappings.tsSymPy's digits returns the base first, then the digits, so the template drops that leading base; for a negative n the base is negated and the digits are those of |n|. A numeral system in the base slot has no counterpart.
sympypackages/oracle/src/mappings.tsSymPy's digits returns the base first, then the digits, so the template drops that leading base; for a negative n the base is negated and the digits are those of |n|. A numeral system in the base slot has no counterpart.
See also: FromDigits, NumeralSystemShape, DigitCount, IntegerString