DigitSum[n]
gives the sum of the decimal digits in the integer n.
DigitSum[n,b]
gives the sum of the base b digits in the integer n.
DigitSum[n,b,k]
gives the sum of the first k base b digits in the integer n.
DigitSum[n,b,-k]
gives the sum of the last k base b digits in the integer n.
DigitSum[n,MixedRadix[blist]]
uses the mixed radix with list of bases blist.


DigitSum
DigitSum[n]
gives the sum of the decimal digits in the integer n.
DigitSum[n,b]
gives the sum of the base b digits in the integer n.
DigitSum[n,b,k]
gives the sum of the first k base b digits in the integer n.
DigitSum[n,b,-k]
gives the sum of the last k base b digits in the integer n.
DigitSum[n,MixedRadix[blist]]
uses the mixed radix with list of bases blist.
Details

- DigitSum[n,b] is equivalent to Total[IntegerDigits[n,b]]. »
- DigitSum discards the sign of n. »
- If k is greater than the number of digits in n, then the sum of all the digits is returned. »
- DigitSum[0,b,k] returns 0 for any base b and digits specified by k. »
- DigitSum automatically threads over lists. »
Examples
open all close allBasic Examples (3)
Scope (8)
DigitSum threads over lists:
Find the digit sum of 7 in different bases:
Find digit sums using a MixedRadix specification:
Properties & Relations (9)
Use IntegerDigits to compute DigitSum:
Use HammingDistance to compute DigitSum in binary:
DigitSum[n,b,-k] gives 0 when k is less than or equal to IntegerExponent[n,b]:
In particular, DigitSum[0,b,k] is always 0:
Use DigitCount to compute DigitSum in binary:
Use DigitCount to compute DigitSum in any base:
IntegerLength and DigitSum give for
in base
:
DigitSum[n,b,k] is equivalent to DigitSum[n,b] when k is greater than the integer length of n in base b:
DigitSum gives the same result for n and IntegerReverse[n,b]:
Related Guides
History
Text
Wolfram Research (2024), DigitSum, Wolfram Language function, https://reference.wolfram.com/language/ref/DigitSum.html.
CMS
Wolfram Language. 2024. "DigitSum." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DigitSum.html.
APA
Wolfram Language. (2024). DigitSum. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DigitSum.html
BibTeX
@misc{reference.wolfram_2025_digitsum, author="Wolfram Research", title="{DigitSum}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/DigitSum.html}", note=[Accessed: 13-August-2025]}
BibLaTeX
@online{reference.wolfram_2025_digitsum, organization={Wolfram Research}, title={DigitSum}, year={2024}, url={https://reference.wolfram.com/language/ref/DigitSum.html}, note=[Accessed: 13-August-2025]}