Task

Take a   Natural Number   in a given base and return the sum of its digits:

   110         sums to   1
   123410   sums to   10
   fe16       sums to   29
   f0e16     sums to   29


MsgBox % sprintf("%d %d %d %d %d`n"
	,SumDigits(1, 10)
	,SumDigits(12345, 10)
	,SumDigits(123045, 10)
	,SumDigits(0xfe, 16)
	,SumDigits(0xf0e, 16) )
 
SumDigits(n,base) {
	sum := 0
	while (n)
	{
		sum += Mod(n,base)
		n /= base
	}
	return sum
}
 
sprintf(s,fmt*) {
	for each, f in fmt
		StringReplace,s,s,`%d, % f
	return s
}