Separate an mpz_t into least and most significant bits.

Marc Glisse marc.glisse at inria.fr
Sun Dec 19 18:59:43 CET 2010


On Sun, 19 Dec 2010, Alexandre Imperatori wrote:

> I have an mpz_t variable holding a number which we can call z and is n bits long.
>
> What I need to do is to derive two mpz_t variables zL (z low) and zH (z high) . Each is n/2 bits long and zL should contain the n/2 least significant bits of z while zH should contain the n/2 most significant bits of z.
>
> There must be some easy way to do that efficiently but I can't pinpoint it correctly.

They are just z/2^m and z%2^m, so:
http://gmplib.org/manual/Integer-Division.html

-- 
Marc Glisse


More information about the gmp-discuss mailing list