Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Dear Monks,

Give me all the abstract database tasks you like, but I feel like I should wear a dunce cap when it comes to binary data.

I'm getting an HDLC-encoded stream from a device. I can decode it okay. Each packet has a format which contains header information followed by binary-packed payloads of various types and sub-types. These are defined from the device's C/C++ code.

I unpack the bytes using the 'a' template for arbitrary binary data. I can view the data in hex and it corresponds to the byte order of the C struct. However, I don't know what to do to convert some of those binary values to numbers like uint32 or int32 values.

For example, one of the uint32 fields in the C struct is a binary flag. The hex value is 0000 0001. Perl says the value is a string, "\0\0\0\x01". How do I convert this to a numeric value without resorting to unpacking each byte and bit-shifting?

Dunce cap. :-) -Mark

In reply to converting artibrary binary data to numeric values by markle

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (2)
    As of 2018-05-21 02:19 GMT
    Find Nodes?
      Voting Booth?