in reply to Little help for the (un)pack challenged
Your description of the input format is lacking.
If those numbers represent the numeric values of the bytes of a string, then this is just reconstructing that string from the information supplied:
my $bytes = pack 'C*', 0x00, 0x00, 0x01, 0x16, 0x7A, 0x53, 0x7C, 0x80;
And that can be decoded as a 64-bit network-order unsigned integer using:
print unpack 'Q', scalar reverse $bytes;; 1196053200000
If you have those numeric values in an array of scalars somewhere, you can skip a level:
print unpack 'Q', pack 'C8', reverse 0x00, 0x00, 0x01, 0x16, 0x7A, 0x +53, 0x7C, 0x80;; 1196053200000
Update: And if you have 5.10 with the fancy new endian modifiers, then:
print unpack 'Q>', pack 'C8', 0x00, 0x00, 0x01, 0x16, 0x7A, 0x53, 0x7 +C, 0x80;; 1196053200000
If you don't have a 64-bit integer capable perl, it takes a little more work:
( $hi, $lo ) = unpack 'NN', $bytes;; print +($hi * 2**32 ) + $lo;; 1196053200000
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Little help for the (un)pack challenged
by Your Mother (Archbishop) on Oct 01, 2009 at 07:54 UTC |