Late to the party, but as far as I can tell, this formula works too:
$$
S\!\left(x\right) = x - 9\sum_{i=1}^N \left\lfloor\tfrac{x}{{10}^i}\right\rfloor, \text{ where } N = \left\lfloor\log_{10}\!\left(x\right)\right\rfloor.
$$
For instance, if we take $x = 7081$, we have $708 + 70 + 7 = 785$, and indeed $7081 - 9 \times 785 = 16$ is the right digit sum (i.e., $7 + 0 + 8 + 1 = 16$).
I think its implementation is simpler and more efficient than the "naive" approach.
Naive approach:
def calc_digit_sum(x: int) -> int:
s = 0
while x > 0:
s += x % 10
x //= 10
return s
This formula's:
def calc_digit_sum_formula(x: int) -> int:
x_ = x
s = 0
while x_ > 0:
x_ //= 10
s += x_
return x - 9 * s
I'm guessing it'd be pretty simple to adapt this formula to other numerical bases (i.e., by substituting all 10 by the new basis value, keeping in mind that $9 = 10 - 1$), but I haven't had the chance to test it out yet.
Also, I don't have a proof on hand for the formula as we speak. I just printed the digit sums for all integers from 0 to 999, happened to "see" the formula, ran a quick (and conclusive) simulation test, and that was it. Probably not that hard to demonstrate, though.
Oh, nevermind, I have the proof here:
$$
\begin{array}{rcl}
S\!\left(x\right)
& = & \sum_{i=0}^N \tfrac{x \mod {10}^{i + 1} - x \mod {10}^i}{{10}^i}\\
& = & \sum_{i=0}^N \tfrac{x - {10}^{i + 1}\left\lfloor\tfrac{x}{{10}^{i + 1}}\right\rfloor - \left(x - {10}^i\left\lfloor\tfrac{x}{{10}^i}\right\rfloor\right)}{{10}^i}\\
& = & \sum_{i=0}^N \left\lfloor\tfrac{x}{{10}^i}\right\rfloor - 10\sum_{i=0}^N \left\lfloor\tfrac{x}{{10}^{i + 1}}\right\rfloor\\
& = & x + \sum_{i=1}^N\left\lfloor\tfrac{x}{{10}^i}\right\rfloor - 10\left(\sum_{i=1}^N\left\lfloor\tfrac{x}{{10}^i}\right\rfloor + \left\lfloor\tfrac{x}{{10}^{N + 1}}\right\rfloor\right)\\
& = & x - 9\sum_{i=1}^N\left\lfloor\tfrac{x}{{10}^i}\right\rfloor.\\
\end{array}
$$
We see that for $10 \leq x < 20$, this formula simplifies to $S\!\left(x\right) = x - 9$, which is consistent with Luhn's checksum algorithm, so that's nice.
Here's another proof, in case the first one wasn't enough... since we have $x = \sum_{j=0}^N a_j {10}^j$, it follows that:
$$
\begin{array}{rcl}
S\!\left(x\right)
& = & x - 9\sum_{i=1}^N\left\lfloor\tfrac{x}{{10}^i}\right\rfloor\\
& = & x - 9\sum_{i=1}^N\sum_{j=i}^N a_j {10}^{j - i}\\
& = & x - 9\sum_{j=1}^N\sum_{i=1}^j a_j {10}^{j - i}\\
& = & x - 9\sum_{j=1}^N a_j {10}^j \sum_{i=0}^{j-1} {10}^{-\left(i + 1\right)}\\
& = & x - 9\sum_{j=1}^N a_j {10}^{j - 1} \tfrac{1 - {\left(1/10\right)}^{j - 1 + 1}}{1 - 1/10}\\
& = & x - \left(\sum_{j=1}^N a_j {10}^j - \sum_{j=1}^N a_j\right)\\
& = & x - \left(x - a_0 - \sum_{j=0}^N a_j + a_0\right)\\
& = & \sum_{j=0}^N a_j.\\
\end{array}
$$
Should be obvious from there that it also applies to any numerical basis.
Now, can we use this formula to extract individual digits? Sure! First, let's just express the $j$-th digit of $x$ as:
$$
a_j = S\!\left(\left\lfloor\tfrac{x}{{10}^j}\right\rfloor\right) - S\!\left(\left\lfloor\tfrac{x}{{10}^{j + 1}}\right\rfloor\right).
$$
We have
$$
\begin{array}{rcl}
S\!\left(\left\lfloor\tfrac{x}{{10}^j}\right\rfloor\right)
& = & \left\lfloor\tfrac{x}{{10}^j}\right\rfloor - 9\sum_{i=1}^N \left\lfloor\left\lfloor\tfrac{x}{{10}^j}\right\rfloor / {10}^i\right\rfloor\\
& = & \left\lfloor\tfrac{x}{{10}^j}\right\rfloor - 9\sum_{i=1}^N \left\lfloor\tfrac{x}{{10}^{i+j}}\right\rfloor\\
& = & \left\lfloor\tfrac{x}{{10}^j}\right\rfloor - 9\sum_{i=j+1}^{N+j} \left\lfloor\tfrac{x}{{10}^i}\right\rfloor\\
& = & \left\lfloor\tfrac{x}{{10}^j}\right\rfloor - 9\sum_{i=j+1}^N \left\lfloor\tfrac{x}{{10}^i}\right\rfloor.\\
\end{array}
$$
Therefore,
$$
\begin{array}{rcl}
a_j
& = & \left\lfloor\tfrac{x}{{10}^j}\right\rfloor - 9\sum_{i=j+1}^N \left\lfloor\tfrac{x}{{10}^i}\right\rfloor - \left\lfloor\tfrac{x}{{10}^{j + 1}}\right\rfloor + 9\sum_{i=j+2}^N \left\lfloor\tfrac{x}{{10}^i}\right\rfloor\\
& = & \left\lfloor\tfrac{x}{{10}^j}\right\rfloor - 10\left\lfloor\tfrac{x}{{10}^{j + 1}}\right\rfloor\\
& = & \left\lfloor\tfrac{x}{{10}^j}\right\rfloor \mod 10,\\
\end{array}
$$
which is poised to be the least controversial result here presented, and also ties nicely with the original formula. Indeed, for the special case $j = 0$, the result simplifies to $a_0 = x - 10\left\lfloor\tfrac{x}{10}\right\rfloor = x \mod 10$, which is self-evident.
// ETA: Added a numerical example, as well as a small note on the origin of this formula.
// ETA2: Added a mathematical proof, and comment on Luhn's Checksum algorithm.
// ETA3: Added a second mathematical proof.
// ETA4: Added a section on individual digit extraction.
// ETA5: Added minor clarification for digit extraction.