calculate sum of digits