I have a binary file and I would like to get the first,second and third field of the line The first field is with offset zero (ofcourse) which has a size of 2 bytes and its format is binary integer format. The second field is offset 2 and size of 2 bytes with binary integer. The third field has offset of 4 with 2 bytes with binary integer data. I was wondering what is the easiest way to do this? I am getting confused on how to use unpack. also, lets assume one of these fields is ASCII -- Offset 15, size 1 --, how could I see this string? Any thoughts? TIA

  • All field sizes are fixed and constant.
  • All fields are contiguous. There is no explicit 'padding' between fields regardless of the data types, size and alignment issues.
  • The binary fields are provided in Big Engined Format which is unsigned
  • ASCII strings are left align, null padded

    In reply to unpack offset question by magawake

    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.