Bill Allombert on Sat, 14 Oct 2023 20:34:12 +0200


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

Re: digits(n,-4)


On Sat, Oct 14, 2023 at 07:24:35PM +0200, Ruud H.G. van Tol wrote:
> 
> ? fromdigits( [1,3,0], -4 )
> % 4

Note that we do need to know that the set of digits is here.

> ? my(n=4, v=[]); while( n=divrem(n,-4), v=concat(n[2],v); n=n[1] ); v
> % [1, 3, 0]
> 
> Is there a better way to do this?

I would start with use digits(n,16) and split the digits.

> Should digits() be changed to support a negative base?

There are too many variants...

Cheers,
Bill.