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


' FB 1.05.0 Win64
 
Function SumDigits(number As Integer, nBase As Integer) As Integer
  If number < 0 Then number = -number  ' convert negative numbers to positive
  If nBase < 2 Then nBase = 2   ' nBase can't be less than 2
  Dim As Integer sum = 0
  While number > 0
    sum += number Mod nBase
    number \= nBase
  Wend
  Return sum
End Function
 
Print "The sums of the digits are:"
Print
Print "1    base 10 :"; SumDigits(1, 10)
Print "1234 base 10 :"; SumDigits(1234, 10)
Print "fe   base 16 :"; SumDigits(&Hfe, 16)
Print "f0e  base 16 :"; SumDigits(&Hf0e, 16) 
Print
Print "Press any key to quit the program"
Sleep