# Counting digit

Di Maria Giovanni calimero22 at yahoo.it
Wed Mar 17 18:33:16 CET 2010

```Ok. Thank you very much to everyone.
Giovanni
>
>
> --- Mar 16/3/10, Décio Luiz Gazzoni Filho <decio at decpp.net>
> ha scritto:
>
> > Da: Décio Luiz Gazzoni Filho <decio at decpp.net>
> > Oggetto: Re: Counting digit
> > A: "Paul Zimmermann" <Paul.Zimmermann at loria.fr>
> > Cc: "Di Maria Giovanni" <calimero22 at yahoo.it>,
> gmp-discuss at gmplib.org
> > Data: Martedì 16 marzo 2010, 14:42
> >
> > On Mar 16, 2010, at 4:44 PM, Paul Zimmermann wrote:
> >
> > >
> > >       Giovanni,
> > >
> > >> I must count digits "1" in a base 18 number.
> > >> Does'it exist a function in Gmp, like
> DigitCount
> > function in Mathematica?
> > >
> > > there is mpz_sizeinbase, but it might be wrong by
> 1
> > for base 18:
> > >
> > > -- Function: size_t mpz_sizeinbase (mpz_t OP,
> int
> > BASE)
> > >     Return the size of OP measured
> > in number of digits in the given
> > >     BASE.  BASE can vary from
> > 2 to 62.  The sign of OP is ignored,
> > >     just the absolute value is
> > used.  The result will be either exact
> > >     or 1 too big.  If BASE is
> > a power of 2, the result is always
> > >     exact.  If OP is zero the
> > return value is always 1.
> > >
> > > You might also use mpz_get_str and strlen for an
> exact
> > result.
> >
> > I think he means counting occurrences of the digit 1
> in the
> > base-18 expansion of the number (that's what his
> explanation
> > sounds like, no idea what DigitCount in Mathematica
> does).
> > Short of doing a base conversion (via mpz_get_str) and
> a
> > while loop which counts 1s, I don't see a way to do
> it.
> >
> > Décio
>
>
>
>

```