Integers conversions

Zdenek Prikryl iprikryl at
Tue Sep 27 11:15:22 CEST 2011

the following situation is a little bit confusing. Let's assume
following situation:

mpz_t mp;
mpz_init_set_ui(mp, 0xffffffffU);
printf("s %x, u %x, s %s\n", mpz_get_ui(mp),
                             mpz_get_str(NULL, 16, mp));

I'd expect that all print outs will be the same (i.e. 0xffffffff). But
the real situation is different and the output is:

s ffffffff, u 7fffffff, s ffffffff

Why the mpz_get_si() returns wrong value? It should return -1 (0xffffffff)?

Zdenek Prikryl

Email: iprikryl at
GPG: 46A8 D633 12C5 D254 24A5 2A13 E631 9140 C209 3303

More information about the gmp-discuss mailing list