Talk:Sum digits of an integer

From Rosetta Code
Revision as of 16:54, 23 July 2012 by Rdm (talk | contribs) (fix silly typo)

Output base

It looks like the base of the output is supposed to be 10. Does that matter at all? --Mwn3d 12:59, 19 July 2012 (UTC)

I agree, for me reading the output as 29 or 0x1d would be the same. For the input the BASE parameter defines how the function interprets the number. Within the computer 0xfe or 254 would both have the same binary representation. I hope that SumDigits(0xfe, 10) would return 11 and that SumDigits(254, 16) would return 29.--Nigel Galloway 11:43, 20 July 2012 (UTC)
I don't understand. "SumDigits(0xfe, 10) would return 11 and that SumDigits(254, 16) would return 29." if sumDigits(0xfe, 16) -> 2910, then how would sumDigits(256, 16) -> 2910? Shouldn't it return 1310? --La Longue Carabine 16:19, 23 July 2012 (UTC)
254 in base 16 has the digits with decimal values 15 and 14. Their sum when expressed in decimal notation is 29. In base 16, using hexadecimal digits, this sum might be represented as 1b = f + e. But we should get a different value for the sum of the digits of 256 -- in base 16, the digits have decimal values 1, 0 and 0, so their sum should be 1. That said, the base used to express the result need not have anything to do with the base used to perform the calculation. --Rdm 16:54, 23 July 2012 (UTC)