Importing integers
Jernej Makovsek
jernej.makovsek at gmail.com
Wed Feb 4 20:44:49 CET 2009
I`m trying to implement "BinaryRead" from Mathematica 7 with the
distinction not only reading a byte but the whole file. If the file in
binary is 10101011 the output should be 2^7 + 2^5 + 2^3 + 2^1 + 2^0.
#include <stdio.h>
#include <gmp.h>
int main()
{
//file pointer
FILE *file;
file = fopen("/home/file", "rb");
//inic
mpz_t t;
mpz_init (t);
size_t mpz_inp_raw(t,file);
gmp_printf("file = %i\nt = %i\n", file, t);
//clear
mpz_clear (t);
fclose(file);
return(0);
}
Output:
file = 151445512
t = -1074788044
where "file" and "t" values change everytime the program is run. Why`s
that? I also tryied doing it with buffers and mpz_import with the same
result.
Since I don`t know what`s wrong it would be of great help if you would
just point me to some reference/book so I could learn it.
Sincerely,
Jernej
More information about the gmp-discuss
mailing list