Bill Allombert on Fri, 19 Oct 2012 17:01:28 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: digits(0)


On Fri, Oct 19, 2012 at 10:46:27AM -0400, Mathieu Carbou wrote:
> Hello,
> 
> I was coding something relative to digits in base 2 and my code crashed
> when the number reached 0 because
> 
> digits(0, 2) = []
> digits(0, 10) = []
> 
> Whereas digits(1,2) = [1]
> 
> I was expecting
> 
> digits(0, 2) = [0]
> digits(0, 10) = [0]
> 
> Why 0 does not deserve to be a digit ? In base 2, or b the first

Because the traditional policy is to delete leading zeros, so the number of digits
of 0 is 0, not 1.

> bit/digit is 1*b^0 or 0*b^0 so why it is not in the resulting vector  ?

Do you mean that digits(1,2) should be [0,1] because 1 is 0*b^1+1*b^0 ?

Cheers,
Bill.