DigitCount[n,b,d]
gives the number of d digits in the base-b representation of n.
DigitCount[n,b,d,len]
gives the number of d digits in the base-b representation of the last len digits of n.
DigitCount[n,b]
gives a list of the numbers of
,
, …,
,
digits in the base-b representation of n.
DigitCount[n]
gives a list of the numbers of
,
, …,
,
digits in the base-10 representation of n.
DigitCount
DigitCount[n,b,d]
gives the number of d digits in the base-b representation of n.
DigitCount[n,b,d,len]
gives the number of d digits in the base-b representation of the last len digits of n.
DigitCount[n,b]
gives a list of the numbers of
,
, …,
,
digits in the base-b representation of n.
DigitCount[n]
gives a list of the numbers of
,
, …,
,
digits in the base-10 representation of n.
Details
- Integer mathematical function, suitable for both symbolic and numerical manipulation.
- DigitCount[n,b,dlist,…] threads over the digits in the list dlist. »
- DigitCount[nlist,…] threads over the digits in the list nlist. »
- DigitCount[n] is equivalent to DigitCount[n,10,Mod[Range[10],10]]. »
- DigitCount[0,b,0] gives 1. »
Examples
open all close allBasic Examples (3)
The number of 1s in binary representation:
DigitCount[2147, 2, 1]DigitCount[2147, 2]Confirm by extending the number in binary:
IntegerDigits[2147, 2]Number of each digit 1, 2, 3, ..., 0 in 100!:
DigitCount[100!]Plot the number of 1s in the base-2 representation:
DiscretePlot[DigitCount[n, 2, 1], {n, 2 ^ 7 - 1}]Scope (2)
Count the number of each of the decimal digits in a number:
DigitCount[122000]Do the same thing, explicitly specifying the base:
DigitCount[122000, 10]Count just the number of zeros:
DigitCount[122000, 10, 0]Count the number of zeros, assuming a 9-digit number:
DigitCount[122000, 10, 0, 9]Count the number of digits 1 and 2 in ternary representation:
DigitCount[242442422, 3, {1, 2}]Get them in the opposite order:
DigitCount[242442422, 3, {2, 1}]Count the number of digits 1 and 2 in the last 12 digits of the ternary representation:
DigitCount[242442422, 3, {1, 2}, 12]Applications (2)
Elements 0 through 24 of the Thue–Morse sequence:
Table[Mod[DigitCount[n - 1, 2, 1], 2], {n, 25}]Compare with the answer given by ThueMorse:
% == Table[ThueMorse[n], {n, 0, 24}]Number of black cells at step t in the rule 90 cellular automaton (binomial coefficients mod 2):
Table[2 ^ DigitCount[t, 2, 1], {t, 0, 10}]Total /@ CellularAutomaton[90, {{1}, 0}, 10]Properties & Relations (8)
DigitCount[n] is equivalent to DigitCount[n,10,Mod[Range[10],10]]:
With[{n = RandomInteger[10^6]}, DigitCount[n] === DigitCount[n, 10, Mod[Range[10], 10]]]DigitCount[n,b,dlist] threads over the digits in the list dlist:
DigitCount[111122555363, 10, {3, 1, 6, 1, 3}]DigitCount[nlist,…] threads over the digits in the list nlist:
DigitCount[{123, 456, 789}]Specify a list of numbers and a base:
DigitCount[{123, 456, 789}, 5]For DigitCount[nlist,b,dlist,…], the result is a list of Length[nlist] lists, each of length Length[dlist]:
DigitCount[{123, 456, 789}, 5, {1, 3}]DigitCount[n,b,d] is effectively Count[IntegerDigits[n,b],d]:
DigitCount[242442422, 3, 0] == Count[IntegerDigits[242442422, 3], 0]DigitCount[n,b,d,len] is effectively Count[PadLeft[IntegerDigits[n,b],len],d]:
DigitCount[242442422, 3, 0, 20] == Count[PadLeft[IntegerDigits[242442422, 3], 20], 0]DigitCount[n,b] equals Values[Counts[IntegerDigits[n,b],Mod[Range[b],b]]:
DigitCount[12345, 6] == Values[Counts[IntegerDigits[12345, 6], Mod[Range[6], 6]]]By extension, this also applies to DigitCount[n] with b==10 on the right-hand side:
DigitCount[12345] == Values[Counts[IntegerDigits[12345, 10], Mod[Range[10], 10]]]DigitCount[0,b,0] gives 1:
Table[DigitCount[0, b, 0], {b, {2, 8, 10, 16}}]This is consistent with the behavior of IntegerDigits[0,b]:
Table[IntegerDigits[0, b], {b, {2, 8, 10, 16}}]DigitCount[n,b,{}] gives {}:
DigitCount[RandomInteger[10 ^ 6], RandomInteger[{2, 16}], {}]Possible Issues (2)
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]The basis argument cannot be list:
DigitCount[100, {3, 5, 7}]Neither can the trailing digits count argument:
DigitCount[100, 3, {0, 1, 2}, {3, 4}]Use Map to manually thread over these arguments if desired:
DigitCount[100, #]& /@ {3, 5, 7}See Also
IntegerLength IntegerDigits DigitSum FromDigits BitAnd IntegerExponent HammingDistance ThueMorse
Function Repository: DigitSum
Tech Notes
Related Guides
Related Links
History
Introduced in 1999 (4.0) | Updated in 2025 (14.2)
Text
Wolfram Research (1999), DigitCount, Wolfram Language function, https://reference.wolfram.com/language/ref/DigitCount.html (updated 2025).
CMS
Wolfram Language. 1999. "DigitCount." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/DigitCount.html.
APA
Wolfram Language. (1999). DigitCount. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DigitCount.html
BibTeX
@misc{reference.wolfram_2026_digitcount, author="Wolfram Research", title="{DigitCount}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/DigitCount.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_digitcount, organization={Wolfram Research}, title={DigitCount}, year={2025}, url={https://reference.wolfram.com/language/ref/DigitCount.html}, note=[Accessed: 13-June-2026]}