Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: forming a word from an array of its bytes

by pidloop (Novice)
on Apr 08, 2021 at 04:29 UTC ( [id://11130991]=note: print w/replies, xml ) Need Help??


in reply to Re: forming a word from an array of its bytes
in thread forming a word from an array of its bytes

Doh! Never thought of combining unpack and pack that way. Works great, many thanks.
  • Comment on Re^2: forming a word from an array of its bytes

Replies are listed 'Best First'.
Re^3: forming a word from an array of its bytes
by jcb (Parson) on Apr 08, 2021 at 23:29 UTC

    The simple way to understand that combination is that pack converts "stuff" to an octet string and unpack converts an octet string to "stuff" according to template strings. Unpacking with a different template than was used for packing reinterprets the octet string, essentially "type-punning" the data. (Type-punning is a C trick where the element of a C union object that is read is not the element that was most recently written.)

    This explanation is how I remember when to use pack and when to use unpack.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11130991]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-05-21 12:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found