Re: 2^[1,3]

Bill Allombert <[email protected]>
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <Z5pAbp1TOsX6J7jQ@seventeen>
On Wed, Jan 29, 2025 at 03:24:02PM +0100, Ruud H.G. van Tol wrote:
> 
> On 2025-01-29 14:42, Bill Allombert wrote:
> > On Wed, Jan 29, 2025 at 02:28:46PM +0100, Ruud H.G. van Tol wrote:
> 
> >> ? vecsum(2^[1,3])
> >> % 10.000000000000000000000000000000000000
> >
> > Use fromdigits:
> > ? fromdigits([1,3],2)
> > % = 10
> 
> Doesn't work:
> 
> ? fromdigits([1,3],2)
> % = 5
> (because 1*2^1 + 3*2^0 = 2+3 = 5)
> 
> 
> The (distinct) digits are exponents, are not positional.
> 2^1 + 2^3 = 10.

Ah sorry!
> Example quest:
> 
> >> How to best convert something like (int) 6131786 to (int) 2^1 + 2^3 + 2^6
> +
> >> 2^7 + 2^8?
> >
> > You can use the binary() function.
> 
> I don't see yet how.

? select(i->i,binary(6131786),1)
%3 = Vecsmall([1,3,4,5,7,8,11,17,20,22])

Cheers,
Bill.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.