Convert a number to base 173

Di Maria Giovanni calimero22 at yahoo.it
Sun May 20 22:03:08 CEST 2012


Hi
Can you help me to translate a number TO base 173 ?
Using the low leve function  "mpn_get_str", if the limb is 1, it works fine.
But if the limb is greater tha 1, it does not work.
Here is my code.


#include <stdio.h>
#include <malloc.h>
#include <gmp.h>
int main(void)

{
   int k;

   mpz_t ru;
   unsigned char *v;
   mp_limb_t indirizzo;
   mp_size_t lunghezza,bytes_scritti;
   v=malloc(100);

   mpz_init(ru);

   mpz_set_str(ru,"1234567",10);
   lunghezza=mpz_size(ru);

   indirizzo=mpz_getlimbn(ru,0);
   bytes_scritti=mpn_get_str(v,173,&indirizzo,lunghezza);

   for(k=0;k<=bytes_scritti-1;k++) {

      printf("%d ",v[k]);
   }
   mpz_clear(ru);

   return 0;
}



I Repeate:  If the number is stored in a limb, it's OK. More limb give problems.
Please Help me!..

Thank you


More information about the gmp-discuss mailing list