Bit flip only function?

Pedro Gimeno gmpdiscuss at formauri.es
Sun Jul 20 20:50:33 UTC 2014


Viktor Kletzhändler wrote, On 2014-07-20 18:22:
> Thanks for the reply.
> 
> mpz_com seems to do more than flipping. 
> 
> For example, for a base-2 number
> mpz_com ( 1111 1111 ) returns ( -1 0000 0000 )
> whereas I would like _dcom ( 1111 1111 ) returns ( 0 ).
> 
> Am I missing something?

For every possible mpz number and bit index, if you test the bit at that
index with mpz_tstbit after doing mpz_com, you get the bit flipped. Note
that mpz_tstbit always returns 1 for bit indexes exceeding the size of
the input number if such number is negative.

But from your description, you seem to want to always get zeros if the
bit index exceeds the bit size of the input number, even after flipping.
Is that what you want?

If so, maybe you can AND the result with a suitable mask using
mpz_sizeinbase as suggested by David Gilles.


More information about the gmp-discuss mailing list