timtowtdi has asked for the wisdom of the Perl Monks concerning the following question:

Maybe the sweet Perlmonks can help me out again on this one.
I'm quite sure, it must be simple, but I can't find out how to do it.
I want my code to convert a little-endian hexvalue (an intel-timestamp) to a decimal value.
I probably have use to pack, or unpack. But so far no succes.

Example result:
Input : B65B7B4000
Output: 1081826230

Thanx in advance,

Tim

The great mistake is to anticipate the outcome of the engagement; Let nature take it's course, and your tools will strike at the right moment.
  • Comment on [pack]little endian timestamp to decimal value

Replies are listed 'Best First'.
Re: [pack]little endian timestamp to decimal value
by Anonymous Monk on Oct 26, 2010 at 19:24 UTC
      "L" is machine dependent. To resolve that ambiguity, switch to "L<" or "V".
      $ perl -le'print unpack "L<", pack "H*", "B65B7B4000"' 1081826230 $ perl -le'print unpack "V", pack "H*", "B65B7B4000"' 1081826230
        Great, I really couldn't find that out myself!

        I actually tried running my script (it's fully Perl, not from commandline) also on a PowerPC. Obviously it returned another decimal value. I understand why, and it is really not a big issue. But I'm just wondering: Is it also possible to tell Perl how to treat a particular variable or value? Or let it run a function as being a in little-endian environment?
        I actually thought that "<" would make Perl do that. But so far, no luck. Or am I doing something wrong?
        Thanks again. You really helped me out again!

        #!/usr/bin/perl -w use strict; my $hexvalue = $ARGV[0]; print unpack "L<", pack "H*", $hexvalue;
        The great mistake is to anticipate the outcome of the engagement; Let nature take it's course, and your tools will strike at the right moment.