V
vaidehikedlaya
Hello,
I am using gmp.h library.
I am trying to put mpz_t variable into char buffer and back. I came
across mpz_import/mpz_export to suffice this purpose. But, I am not
very clear about using these functions. I am not getting the right
result for the program below. In the program I have included the
code(present in the gmp document, in the description of mpz_export
function)
numb = 8*size - nail;
count = (mpz_sizeinbase (z, 2) + numb-1) / numb;
p = malloc (count * size);
to determine the size of the char buffer. In the above code is "size"
the size of char buffer.
Could you please let me know what is wrong in the code below.
Is there any other way to place mpz_t variable into char buffer, and
the buffer data back to mpz_t variable.
# include<stdio.h>
# include<gmp.h>
int main(){
int base=10;
mpz_t op;
mpz_t z;
mpz_init_set_str(op,"21896",base);
/*Determinimg the size of the char buffer*/
long size = sizeof(char);
long numb = 8*size - 0;
long count = (mpz_sizeinbase (op, 2) + numb-1) / numb;
char *p = (char *)malloc (count * size);
/* The mpz variable is put into buffer p, and back into mpz variable*/
mpz_export(p,NULL,1,1,0,0,op);
mpz_import (z,count*size , 1, sizeof(p), 0, 0, p);
gmp_printf("the value of z : %Zd\n",z);
}
Thanks in advance.
I am using gmp.h library.
I am trying to put mpz_t variable into char buffer and back. I came
across mpz_import/mpz_export to suffice this purpose. But, I am not
very clear about using these functions. I am not getting the right
result for the program below. In the program I have included the
code(present in the gmp document, in the description of mpz_export
function)
numb = 8*size - nail;
count = (mpz_sizeinbase (z, 2) + numb-1) / numb;
p = malloc (count * size);
to determine the size of the char buffer. In the above code is "size"
the size of char buffer.
Could you please let me know what is wrong in the code below.
Is there any other way to place mpz_t variable into char buffer, and
the buffer data back to mpz_t variable.
# include<stdio.h>
# include<gmp.h>
int main(){
int base=10;
mpz_t op;
mpz_t z;
mpz_init_set_str(op,"21896",base);
/*Determinimg the size of the char buffer*/
long size = sizeof(char);
long numb = 8*size - 0;
long count = (mpz_sizeinbase (op, 2) + numb-1) / numb;
char *p = (char *)malloc (count * size);
/* The mpz variable is put into buffer p, and back into mpz variable*/
mpz_export(p,NULL,1,1,0,0,op);
mpz_import (z,count*size , 1, sizeof(p), 0, 0, p);
gmp_printf("the value of z : %Zd\n",z);
}
Thanks in advance.