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


 
EnableExplicit
 
Procedure.i SumDigits(Number.q, Base)
  If Number < 0 : Number = -Number : EndIf; convert negative numbers to positive
  If Base < 2 : Base = 2 : EndIf ; base can't be less than 2
  Protected sum = 0
  While Number > 0
    sum + Number % Base
    Number / Base
  Wend
  ProcedureReturn sum
EndProcedure
 
If OpenConsole()
  PrintN("The sums of the digits are:")
  PrintN("")
  PrintN("1    base 10 : " + SumDigits(1, 10))
  PrintN("1234 base 10 : " + SumDigits(1234, 10))
  PrintN("fe   base 16 : " + SumDigits($fe, 16))
  PrintN("f0e  base 16 : " + SumDigits($f0e, 16)) 
  PrintN("")
  PrintN("Press any key to close the console")
  Repeat: Delay(10) : Until Inkey() <> ""
  CloseConsole()
EndIf
 