Function Repository Resource:

# DigitSum

Find the sum of digits in the positional representation of an integer

Contributed by: Wolfram|Alpha Math Team
 ResourceFunction["DigitSum"][n] gives the sum of digits in the base-10 representation of the integer n. ResourceFunction["DigitSum"][n,b] gives the sum of digits in the base-b representation of integer n.

## Details and Options

ResourceFunction["DigitSum"] ignores the sign of its input.

## Examples

### Basic Examples (3)

Compute a digit sum in base 10:

 In[1]:=
 Out[1]=

Compute another digit sum:

 In[2]:=
 Out[2]=

Compute a digit sum in another numerical base:

 In[3]:=
 Out[3]=

Compare this to the output of IntegerDigits:

 In[4]:=
 Out[4]=
 In[5]:=
 Out[5]=

### Properties and Relations (2)

DigitSum ignores the sign of its input:

 In[6]:=
 Out[6]=

The digit sum of 0 is 0 in any base:

 In[7]:=
 Out[7]=
 In[8]:=
 Out[8]=

## Publisher

Wolfram|Alpha Math Team

## Version History

• 4.0.0 – 23 March 2023
• 3.1.0 – 11 May 2021
• 3.0.0 – 24 January 2020
• 2.0.0 – 06 September 2019
• 1.0.0 – 31 July 2019