DigitSum
✖
DigitSum
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 allclose allBasic Examples (3)Summary of the most common use cases
Find the sum of the decimal digits in :

https://wolfram.com/xid/0bdpl07fe-ruupcq

Find the sum of the binary digits in :

https://wolfram.com/xid/0bdpl07fe-cfp0m9

Find the digit sum in a mixed radix system:

https://wolfram.com/xid/0bdpl07fe-otn38h

Scope (8)Survey of the scope of standard use cases

https://wolfram.com/xid/0bdpl07fe-bx2jiu


https://wolfram.com/xid/0bdpl07fe-ixvfu2

DigitSum threads over lists:

https://wolfram.com/xid/0bdpl07fe-w7f2d8

Find the digit sum of 7 in different bases:

https://wolfram.com/xid/0bdpl07fe-7amg26


https://wolfram.com/xid/0bdpl07fe-8udmv8


https://wolfram.com/xid/0bdpl07fe-ivp7ku

Find digit sums using a MixedRadix specification:

https://wolfram.com/xid/0bdpl07fe-nrkbg0


https://wolfram.com/xid/0bdpl07fe-2vnye

Exact values are generated at integers:

https://wolfram.com/xid/0bdpl07fe-20lxp

Applications (1)Sample problems that can be solved with this function
Properties & Relations (9)Properties of the function, and connections to other functions
Use IntegerDigits to compute DigitSum:

https://wolfram.com/xid/0bdpl07fe-n8mhqv


https://wolfram.com/xid/0bdpl07fe-bcjear

Use HammingDistance to compute DigitSum in binary:

https://wolfram.com/xid/0bdpl07fe-f39aoi


https://wolfram.com/xid/0bdpl07fe-j11muw

DigitSum[n,b,-k] gives 0 when k is less than or equal to IntegerExponent[n,b]:

https://wolfram.com/xid/0bdpl07fe-k77b2e


https://wolfram.com/xid/0bdpl07fe-s0uzwr

In particular, DigitSum[0,b,k] is always 0:

https://wolfram.com/xid/0bdpl07fe-rx9tac


https://wolfram.com/xid/0bdpl07fe-lj5jjx

Use DigitCount to compute DigitSum in binary:

https://wolfram.com/xid/0bdpl07fe-0wii76


https://wolfram.com/xid/0bdpl07fe-doqxgz

Use DigitCount to compute DigitSum in any base:

https://wolfram.com/xid/0bdpl07fe-weh4dn


https://wolfram.com/xid/0bdpl07fe-phbev

IntegerLength and DigitSum give for
in base
:

https://wolfram.com/xid/0bdpl07fe-ke274n


https://wolfram.com/xid/0bdpl07fe-0vchdo

DigitSum[n,b,k] is equivalent to DigitSum[n,b] when k is greater than the integer length of n in base b:

https://wolfram.com/xid/0bdpl07fe-m2jxd2


https://wolfram.com/xid/0bdpl07fe-h7ey9p

DigitSum gives the same result for n and IntegerReverse[n,b]:

https://wolfram.com/xid/0bdpl07fe-eip8oo


https://wolfram.com/xid/0bdpl07fe-2xik3u


https://wolfram.com/xid/0bdpl07fe-v8pvfm

Wolfram Research (2024), DigitSum, Wolfram Language function, https://reference.wolfram.com/language/ref/DigitSum.html.
Text
Wolfram Research (2024), DigitSum, Wolfram Language function, https://reference.wolfram.com/language/ref/DigitSum.html.
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.
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
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: 26-March-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: 26-March-2025
]}