I have to add the I've always worked with ASCII strings, so pack and unpack are still magic for me, but I'll keep trying!

No I've tried to unpack the following header:
Position(bytes) Datatype 0 - 7 long 8 - 15 long 16 - 23 long 24 - 31 long 32 - 39 long 40 - 43 int 44 - 51 long
I checked with 'od -l' (on a Unix system):
0000000 0 2000 0 200 0000020 0 455800 0 4 0000040 0 8 2000 275 0000060 281946600 167772160 0000065
I only know that the 6th value is 2000, which is now the 11th value, so I get the impression that it is expected that a long is only 4 bytes, does that make any sense ?

Now, when I do (on Linux)
my @vals = unpack("N*", $binrec ) ; print "@vals" ;
Output
0 2000 0 200 0 455800 0 4 0 8 2000 275 281946600
I get the same values as od except for the last value!
The last thing that confuses me is how to convert a singed/unsiged integer from big to little endian ?

LuCa

In reply to Re: swap binary data from big to little Endian by jeanluca
in thread swap binary data from big to little Endian by jeanluca

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.