Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: (tye)Re: pack 64 bit int ?

by frankied (Beadle)
on May 01, 2002 at 21:05 UTC ( #163389=note: print w/replies, xml ) Need Help??


in reply to (tye)Re: pack 64 bit int ?
in thread pack 64 bit int ?

(wondering how I missed that node when searching)

I did this for unpack:

my ($int1,$int2)=unpack('NN',shift()); my $sign=($int1&0x80000000); if($sign) { $int1^=-1; $int2^=-1; ++$int2; $int2%=2**32; ++$int1 unless $int2; } my $i=new Math::BigInt $int1; $i*=2**32; $i+=$int2; $i=-$i if $sign;
your 2's complement conversion looks less painful, though.

update:
shamelessly (thank you!) stealing ideas from tye's unpack, I would now write down a pack like:

my $i=new Math::BigInt shift(); my($int1,$int2)=do { if ($i<0) { $i=-1-$i; (~(int($i/2**32)%2**32),~int($i%2**32)); } else { (int($i/2**32)%2**32,int($i%2**32)); } }; pack('NN',$int1,$int2);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://163389]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2021-09-20 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?