Initialise an integer with all bits set to 1.

Kevin Ryde user42@zip.com.au
Tue, 01 Jul 2003 08:59:23 +1000


"Sisyphus" <kalinabears@iinet.net.au> writes:
>
> At the moment I'm initialising the integer to zero with
> mpz_init2() and then looping through each bit and setting it to 1 with
> mpz_setbit().

A value 2^n-1 can be done in the expected way with mpz_set_ui(z,1),
mpz_mul_2exp(z,z,n) and mpz_sub_ui(z,z,1).  Should be faster than
mpz_setbit, especially since the latter probably ends up doing
repeated reallocs.