IntegerDigits

IntegerDigits[n]

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 allclose all

Basic Examples  (3)

Find digits in base 10:

Find digits in base 2:

Find digits in a mixed radix system:

Scope  (8)

Bases larger than 10 can be used:

IntegerDigits threads itself over elements of lists:

Find the digits of 7 in different bases:

By default, IntegerDigits includes no leading zeros:

Pad all digit lists to be length 3:

Find only the last 4 digits:

Find digits using a MixedRadix specification:

Find only the last 2 digits:

Applications  (4)

Leading digits of factorials:

ChampernowneNumber has a decimal expansion that is a concatenation of consecutive integers:

Compare to ChampernowneNumber:

Cantor set construction:

Construct a van der Corput sequence:

The sequence forms a dense set that is equidistributed in the unit interval:

Build a Halton sequence:

Illustrate low-discrepancy property of the sequence:

Properties & Relations  (4)

Find all combinations of 3 binary digits:

Pad digit lists to be the same length:

The sign is ignored:

Express an amount of seconds in hours, minutes, and seconds:

It can also be obtained with NumberDecompose:

Perform the same computation using Quantity objects:

Neat Examples  (1)

Leading digits of factorials in base 100:

Wolfram Research (1991), IntegerDigits, Wolfram Language function, https://reference.wolfram.com/language/ref/IntegerDigits.html (updated 2015).

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_2024_integerdigits, author="Wolfram Research", title="{IntegerDigits}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/IntegerDigits.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_integerdigits, organization={Wolfram Research}, title={IntegerDigits}, year={2015}, url={https://reference.wolfram.com/language/ref/IntegerDigits.html}, note=[Accessed: 21-November-2024 ]}