Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

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!
  • 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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (12)
    As of 2015-07-02 14:01 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (41 votes), past polls