Node:Integer Import and Export, Next:Miscellaneous Integer Functions, Previous:Integer Random Numbers, Up:Integer Functions
mpz_t
variables can be converted to and from arbitrary words of binary
data with the following functions.
void mpz_import (mpz_t rop, size_t count, int order, int size, int endian, size_t nails, const void *op) | Function |
Set rop from an array of word data at op.
The parameters specify the format of the data. count many words are read, each size bytes. order can be 1 for most significant word first or -1 for least significant first. Within each word endian can be 1 for most significant byte first, -1 for least significant first, or 0 for the native endianness of the host CPU. The most significant nails bits of each word are skipped, this can be 0 to use the full words. There are no data alignment restrictions on op, any address is allowed. Here's an example converting an array of unsigned long a[20]; mpz_t z; mpz_import (z, 20, 1, sizeof(a[0]), 0, 0, a); This example assumes the full |
void *mpz_export (void *rop, size_t *count, int order, int size, int endian, size_t nails, mpz_t op) | Function |
Fill rop with word data from op.
The parameters specify the format of the data produced. Each word will be size bytes and order can be 1 for most significant word first or -1 for least significant first. Within each word endian can be 1 for most significant byte first, -1 for least significant first, or 0 for the native endianness of the host CPU. The most significant nails bits of each word are unused and set to zero, this can be 0 to produce full words. The number of words produced is written to If op is non-zero then the most significant word produced will be
non-zero. If op is zero then the count returned will be zero and
nothing written to rop. If rop is There are no data alignment restrictions on rop, any address is allowed. The sign of op is ignored, just the absolute value is used. When an application is allocating space itself the required size can be
determined with a calculation like the following. Since numb = 8*size - nail; count = (mpz_sizeinbase (z, 2) + numb-1) / numb; p = malloc (count * size); |