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[9 ^ 1000 + 1]DigitSum[58127, 16]DigitSum threads over lists:
DigitSum[{6, 7, 2}, 2]Find the digit sum of 7 in different bases:
DigitSum[7, {2, 3, 4}]DigitSum[6345354, 10, 4]DigitSum[6345354, 10, -4]Find digit sums using a MixedRadix specification:
DigitSum[137, MixedRadix[{3, 12}]]DigitSum[1084, MixedRadix[{17, 15, 11}], -2]Exact values are generated at integers:
DigitSum[35297]Applications (1)
Properties & Relations (9)
Use IntegerDigits to compute DigitSum:
Total[IntegerDigits[37103]]DigitSum[37103]Use HammingDistance to compute DigitSum in binary:
HammingDistance[IntegerDigits[143, 2], 0IntegerDigits[143, 2]]DigitSum[143, 2]DigitSum[n,b,-k] gives 0 when k is less than or equal to IntegerExponent[n,b]:
DigitSum[123000, 10, -3]IntegerExponent[123000, 10]In particular, DigitSum[0,b,k] is always 0:
DigitSum[0, 10, -3]IntegerExponent[0]Use DigitCount to compute DigitSum in binary:
DigitCount[2147, 2, 1]DigitSum[2147, 2]Use DigitCount to compute DigitSum in any base:
DigitCount[2147].Mod[Range[10], 10]DigitSum[2147]IntegerLength and DigitSum give
for
in base
:
IntegerLength[(10 ^ 17 - 1) / (10 - 1)]DigitSum[(10 ^ 17 - 1) / (10 - 1)]DigitSum[n,b,k] is equivalent to DigitSum[n,b] when k is greater than the integer length of n in base b:
DigitSum[123456, 10, 7]IntegerLength[123456, 10]DigitSum gives the same result for n and IntegerReverse[n,b]:
DigitSum[263, 5]DigitSum[IntegerReverse[263, 5], 5]DigitSum[-3134]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_2026_digitsum, author="Wolfram Research", title="{DigitSum}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/DigitSum.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_digitsum, organization={Wolfram Research}, title={DigitSum}, year={2024}, url={https://reference.wolfram.com/language/ref/DigitSum.html}, note=[Accessed: 12-June-2026]}