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 allclose 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]:
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