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


      *FLOAT64
      PRINT "Digit sum of 1 (base 10) is "; FNdigitsum(1, 10)
      PRINT "Digit sum of 12345 (base 10) is "; FNdigitsum(12345, 10)
      PRINT "Digit sum of 9876543210 (base 10) is "; FNdigitsum(9876543210, 10)
      PRINT "Digit sum of FE (base 16) is "; ~FNdigitsum(&FE, 16) " (base 16)"
      PRINT "Digit sum of F0E (base 16) is "; ~FNdigitsum(&F0E, 16) " (base 16)"
      END
 
      DEF FNdigitsum(n, b)
      LOCAL q, s
      WHILE n <> 0
        q = INT(n / b)
        s += n - q * b
        n = q
      ENDWHILE
      = s