Pick up an hex digit from a mpz_t integer

Sam Rawlins sam.rawlins at gmail.com
Sat Jul 27 19:45:14 CEST 2013

Your example does not use any mpz_t integers, but I'll give you the benefit
of the doubt, and assume you mean that number is an mpz_t, and not a char*:

If you have an mpz_t, number, you can convert to a hexadecimal
representation in a char* with mpz_get_str() [1], like so:

    mpz_get_str(my_char_pointer, 16, number);

>From there, you can use standard C and string functions to pluck out the
hexadecimal digit you are looking for.

[1] http://gmplib.org/manual/Converting-Integers.html#Converting-Integers

On Sat, Jul 27, 2013 at 10:19 AM, Ramón T. B. <framontb at yahoo.es> wrote:

> Hello all,
>    I need a function to pick up an hex digit from a mpz_t integer. For
> example:
> int pick_hex(mpz_t number, int position);
> For example:
> number = "123456789abcdef";
> position = 3;
> solution = pick_hex(number, position);  // solution = c
> How I can achieve that?
> Thanks in advance !
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-discuss

Sam Rawlins

More information about the gmp-discuss mailing list