Bill Allombert on Mon, 29 Jan 2018 21:44:04 +0100


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

Re: Optional parameter to digits() / binary() functions for fixed vector size output


On Mon, Jan 29, 2018 at 09:28:29PM +0100, Jérôme Raulin wrote:
> Dear all,
> 
> Would it be possible to add an optional parameter len to digits() and
> binary() functions in order to pad the output on the left with zeros to
> give a vector of at least length len.
> 
> It is sometime useful to iterate over all representations of b^n-1 in base b
> (usually in base 2) and it would be useful to have digits(1, b, n) to return
> [0, 0, ...,1] instead of [1].

Hello Jérôme,

You can do 

? Vec(binary(3),-5)
%9 = [0,0,0,1,1]
? Vec(digits(17),-5)
%10 = [0,0,0,1,7]

If you prefer least significant digits first, do
? Vecrev(digits(17),5)
%12 = [7,1,0,0,0]

Cheers,
Bill.