A newbie question
Paul Leyland
paul at leyland.vispa.com
Mon Aug 17 17:03:30 CEST 2009
The standard way is to evaluate (n / 10^x) % 10. Conversion of that
expression into calls of mpz_foo() is left as a rather simple exercise.
If n and x are VERY large you may be worried about efficiency.
Personally, I'd write the simple code first and only worry about
optimization if it turns out to be needed.
Paul
On Mon, 2009-08-17 at 07:59 -0600, David Gillies wrote:
> Digit extraction in this case is tantamount to base conversion. For a
> non-power of two base this is hard.
>
> On Sun, Aug 16, 2009 at 8:09 PM, Bird, John<John.Bird at ca.com> wrote:
> > Hi Guys
> >
> >
> >
> > I'm looking through the manual for a function that pulls out the Xth
> > digit of an int.
> >
> > So something like this:
> >
> >
> >
> > unsigned long uslong;
> >
> >
> >
> > mpz_set_str(n, "111111111111111911111", 10);
> >
> > uslong = mpz_get_index_ui(n, 5);
> >
> >
> >
> > uslong would now equal 9
> >
> >
> >
> > The closest thing in the manual I can find is mpz_getlimbn. Is this the
> > function I am looking for? If so, can anyone suggest an efficient way of
> > calculating an "index" from that?
> >
> >
> >
> > Many thanks,
> >
> > John
> >
> > _______________________________________________
> > gmp-discuss mailing list
> > gmp-discuss at gmplib.org
> > https://gmplib.org/mailman/listinfo/gmp-discuss
> >
>
>
>
More information about the gmp-discuss
mailing list