gives a list of the decimal digits in the integer n.
IntegerDigits[n,b]
gives a list of the base b digits in the integer n.
IntegerDigits[n,b,len]
pads the list on the left with zeros to give a list of length len.
IntegerDigits[n,MixedRadix[blist]]
uses the mixed radix with list of bases blist.
IntegerDigits
gives a list of the decimal digits in the integer n.
IntegerDigits[n,b]
gives a list of the base b digits in the integer n.
IntegerDigits[n,b,len]
pads the list on the left with zeros to give a list of length len.
IntegerDigits[n,MixedRadix[blist]]
uses the mixed radix with list of bases blist.
Details
- IntegerDigits gives the most significant digit first, as in standard positional notation.
- IntegerDigits[n] discards the sign of n. »
- If len is less than the number of digits in n, then the len least significant digits are returned.
- IntegerDigits[0] gives {0}. »
- FromDigits can be used as the inverse of IntegerDigits.
Examples
open all close allBasic Examples (3)
Scope (9)
Arbitrarily large bases can be used:
IntegerDigits[58127, 123]Find digits in a mixed radix system:
bases = {24, 60, 60};
digits = IntegerDigits[102341, MixedRadix[bases]]The place values are incremental products of the bases in the list:
placeVals = Reverse[FoldList[Times, 1, Reverse[bases]]]Reconstruct the original value:
digits.placeValsThere will never be more than Length[bases]+1 digits; the highest-value digit can grow arbitrarily large:
IntegerDigits[10 ^ 12, MixedRadix[bases]]IntegerDigits threads itself over elements of lists:
IntegerDigits[{6, 7, 2}, 2]Find the digits of 7 in different bases:
IntegerDigits[7, {2, 3, 4}]By default, IntegerDigits includes no leading zeros:
IntegerDigits[Range[0, 7], 2]Pad all digit lists to be length 3:
IntegerDigits[Range[0, 7], 2, 3]IntegerDigits[6345354, 10, 4]Find digits using a MixedRadix specification:
IntegerDigits[137, MixedRadix[{3, 12}]]IntegerDigits[1084, MixedRadix[{17, 15, 11}], 2]Applications (4)
Table[First[IntegerDigits[n!]], {n, 50}]ChampernowneNumber has a decimal expansion that is a concatenation of consecutive integers:
Join@@Table[IntegerDigits[i], {i, 30}]Compare to ChampernowneNumber:
N[ChampernowneNumber[10], Length[%]]Table[If[FreeQ[IntegerDigits[n - 1, 3], 1], 1, 0], {n, 27}]Construct a van der Corput sequence:
vanderCorput[b_, n_] := FromDigits[IntegerDigits[n, b], 1 / b] / bThe sequence forms a dense set that is equidistributed in the unit interval:
QuantilePlot[Table[vanderCorput[2, n], {n, 50}], UniformDistribution[]]Halton[n_] := {vanderCorput[2, n], vanderCorput[3, n]}Illustrate low-discrepancy property of the sequence:
Table[Circle[Halton[n], 0.01], {n, 256}]//GraphicsProperties & Relations (5)
IntegerDigits[0] gives {0}:
IntegerDigits[0]Find all combinations of 3 binary digits:
Table[IntegerDigits[i, 2, 3], {i, 0, 7}]Tuples[{0, 1}, 3]Pad digit lists to be the same length:
PadLeft[Table[IntegerDigits[i ^ 2, 2], {i, 5}]]IntegerDigits[-3134]Express an amount of seconds in hours, minutes, and seconds:
IntegerDigits[98534, MixedRadix[{24, 60, 60}]]It can also be obtained with NumberDecompose:
NumberDecompose[98534, {86400, 3600, 60, 1}]Perform the same computation using Quantity objects:
UnitConvert[Quantity[98534, "Seconds"], MixedUnit[{"Days", "Hours", "Minutes", "Seconds"}]]Possible Issues (1)
DigitCount and IntegerDigits consider 0 to consist of a single digit:
{DigitCount[0, 10, 0], IntegerDigits[0]}IntegerLength, by contrast, considers 0 to have no digits:
IntegerLength[0, 2]See Also
FromDigits IntegerString NumberExpand DigitCount IntegerLength DigitSum NumberDecompose RealDigits NumberDigit BaseForm NumberForm RomanNumeral IntegerReverse PalindromeQ IntegerExponent IntegerPart ContinuedFraction Tuples BitAnd BitOr BitLength
Function Repository: NthDigit GrayCode ToNegabinary BinaryCodedTernary
Related Links
-

MathWorld
-

An Elementary Introduction to the Wolfram Language
: More about Numbers
-

An Elementary Introduction to the Wolfram Language
: Operations on Lists
-

An Elementary Introduction to the Wolfram Language
: Pure Anonymous Functions
-

An Elementary Introduction to the Wolfram Language
: Writing Good Code
-

NKS|Online
(A New Kind of Science)
History
Introduced in 1991 (2.0) | Updated in 1996 (3.0) ▪ 2003 (5.0) ▪ 2015 (10.2)
Text
Wolfram Research (1991), IntegerDigits, Wolfram Language function, https://reference.wolfram.com/language/ref/IntegerDigits.html (updated 2015).
CMS
Wolfram Language. 1991. "IntegerDigits." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/IntegerDigits.html.
APA
Wolfram Language. (1991). IntegerDigits. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/IntegerDigits.html
BibTeX
@misc{reference.wolfram_2026_integerdigits, author="Wolfram Research", title="{IntegerDigits}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/IntegerDigits.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_integerdigits, organization={Wolfram Research}, title={IntegerDigits}, year={2015}, url={https://reference.wolfram.com/language/ref/IntegerDigits.html}, note=[Accessed: 13-June-2026]}