gmp_libmpz_out_raw Method |
Namespace: Math.Gmp.Native
The integer is written in a portable format, with 4 bytes of size information, and that many bytes of limbs. Both the size and the limbs are written in decreasing significance order (i.e., in big-endian).
The output can be read with mpz_inp_raw.
The output of this can not be read by mpz_inp_raw from GMP 1, because of changes necessary for compatibility between 32-bit and 64-bit machines.
// Create, initialize, and set the value of op to 123456 (0x1E240). mpz_t op = new mpz_t(); gmp_lib.mpz_init_set_ui(op, 0x1E240); // Get a temporary file. string pathname = System.IO.Path.GetTempFileName(); // Open temporary file for writing. ptr<FILE> stream = new ptr<FILE>(); _wfopen_s(out stream.Value.Value, pathname, "w"); // Write op to temporary file, and assert that the number of bytes written is 7. Assert.IsTrue(gmp_lib.mpz_out_raw(stream, op) == 7); // Close temporary file. fclose(stream.Value.Value); // Assert that the content of the temporary file. byte[] r = System.IO.File.ReadAllBytes(pathname); Assert.IsTrue(r[0] == 0 && r[1] == 0 && r[2] == 0 && r[3] == 3 && r[4] == 0x01 && r[5] == 0xE2 && r[6] == 0x40); // Delete temporary file. System.IO.File.Delete(pathname); // Release unmanaged memory allocated for op. gmp_lib.mpz_clear(op);