Creating mpz_t from binary data

Saju Pillai saju.pillai at
Wed Mar 17 16:47:43 CET 2010

Marc Glisse wrote:
> On Wed, 17 Mar 2010, Saju Pillai wrote:
>> I am new to GMP. I receive a multi precision big endian integer 
>> represented in two's complement. I am on a little endian machine. How 
>> can I create a mpz_t using this data ?
>> Will reversing the data bytes to create a little endian representation 
>> and calling mpz_set_str(rop, data, 2) work ?. Since this is binary 
>> data,  NULs may occur anywhere in the data. How do you suggest I 
>> proceed ?
>> The mpint data type described at 
>> (SSH architecture rfc) is 
>> the data format I am dealing with.
> Hello,
> did you try ?

Yes, this is what I am looking for. I happened to find mpz_import() just 
after sending out the query. Thanks for replying though.


More information about the gmp-discuss mailing list