|
Posted by Golan on June 12, 2008, 9:52 am
Please log in for more thread options
How do i unpack "long long" int type ( 8 bytes ) ?
this unpack("l8",$var) returns spaces .
but unpack("l4,substr($var,4)) returns the correct value .
Thanks
Golan
|
|
Posted by Ben Morrow on June 12, 2008, 1:20 pm
Please log in for more thread options
> How do i unpack "long long" int type ( 8 bytes ) ?
'q'. Note that your perl needs to be built with 64bit integers.
Ben
--
Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read.
ben@morrow.me.uk Groucho Marx
|
|
Posted by Ted Zlatanov on June 12, 2008, 3:31 pm
Please log in for more thread options
>> How do i unpack "long long" int type ( 8 bytes ) ?
BM> 'q'. Note that your perl needs to be built with 64bit integers.
That seems like an unnecessary restriction. Is it really impossible for
a 32-bit Perl to decode 64-bit numbers? We know the endianness, is
there anything else needed?
Ted
|
|
Posted by Ben Morrow on June 12, 2008, 4:35 pm
Please log in for more thread options
>
> >> How do i unpack "long long" int type ( 8 bytes ) ?
>
> BM> 'q'. Note that your perl needs to be built with 64bit integers.
>
> That seems like an unnecessary restriction. Is it really impossible for
> a 32-bit Perl to decode 64-bit numbers? We know the endianness, is
> there anything else needed?
Err... a type to hold the value in? While you can hold numbers greater
than 2**32 in a NV, NVs only have 53 bits of precision (or, at least,
they do here) so they can't hold values up to 2**64 with integer
precision.
If you know the endianness and know the value will be small, or if you
use bigint, you can easily unpack as two longs and combine them.
Ben
--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] ben@morrow.me.uk
|
|
Posted by Uri Guttman on June 12, 2008, 5:44 pm
Please log in for more thread options
>>
>> That seems like an unnecessary restriction. Is it really impossible for
>> a 32-bit Perl to decode 64-bit numbers? We know the endianness, is
>> there anything else needed?
BM> Err... a type to hold the value in? While you can hold numbers greater
BM> than 2**32 in a NV, NVs only have 53 bits of precision (or, at least,
BM> they do here) so they can't hold values up to 2**64 with integer
BM> precision.
good point.
BM> If you know the endianness and know the value will be small, or if you
BM> use bigint, you can easily unpack as two longs and combine them.
but that isn't really unpacking them. it is reordering bytes and it
still is a byte string. 32 bit perl has no direct way to interact with
64 bit numbers (some modules do xs trickery to hold 64 bit values like
Time::HiRes). so unpacking 8 bytes to 64 bits makes no sense in 32 bit
perl.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
|
| Similar Threads | Posted | | How to unpack long long ? | June 12, 2008, 9:51 am |
| 'long long integer' in Perl | February 15, 2006, 2:30 pm |
| How long is too long for cgi script? | April 22, 2005, 12:07 pm |
| long lines | October 28, 2004, 12:25 pm |
| Version? Getopt::Long | October 4, 2004, 3:00 pm |
| How long to complete: while ($i<1e10) | November 6, 2004, 9:16 am |
| FAQ 5.14 Why do I sometimes get an "Argument list too long" when I use <*>? | February 9, 2005, 6:03 pm |
| FAQ 5.15 Why do I sometimes get an "Argument list too long" when I use <*>? | April 24, 2005, 5:03 am |
| GetOptions::Long question | June 1, 2005, 4:38 pm |
| Long running CGI script | June 17, 2005, 4:13 am |
|