[Israel.pm] packing and unpacking large numbers

Shmuel Fomberg semuelf at 012.net.il
Thu Jul 26 13:17:05 PDT 2007


>From: Yona Shlomo [mailto:yona at cs.technion.ac.il]
>Sent: Thursday, July 26, 2007 3:43 PM

>3. pack the number into a C long long int data type (i.e., a
>64 bite representation).

You can always take the stringy path, that is: (tested)
$x = Math::BigInt->new('123456789123');
$str = $x->as_bin();
substr($str, 0, 2) = '0' x (64 - length($str) + 2);
$binary = pack "B*", $str;

just make sure that you have the right byte order.
(big/little indeans and so)

Have fun.
Shmuel.






More information about the Perl mailing list