Click or drag to resize
gmp_libmpz_out_raw Method
Output op on stdio stream stream, in raw binary format.

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static size_t mpz_out_raw(
	ptr<FILE> stream,
	mpz_t op
)

Parameters

stream
Type: Math.Gmp.NativeptrFILE
Pointer to file streama.
op
Type: Math.Gmp.Nativempz_t
The operand integer.

Return Value

Type: size_t
Return the number of bytes written, or if an error occurred, return 0.
Remarks

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.

Examples
// 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);
See Also