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

Re: further subdivision of unpack result

by BrowserUk (Patriarch)
on Apr 13, 2011 at 03:53 UTC ( [id://899096]=note: print w/replies, xml ) Need Help??


in reply to further subdivision of unpack result

Why are you converting to bits only then to have to convert back to bytes?

Reading between the lines of your post, you could use this to get at the bytes:

($id, @bytes) = unpack ("A16 x72 C*", $data);

and then just access the them via the array.

But then, looking at the way you are numbering your 4 bytes: (byte2, byte1, byte4, byte3) it seems likely that each group of 4 bytes is actually a little endian 32-bit value. In which case, you can skip the bytes step also and do:

($id, @dwords) = unpack ("A16 x72 (L<)*", $data);

It's a lot simpler to use the built-in facilities :)


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: further subdivision of unpack result
by ikegami (Patriarch) on Apr 13, 2011 at 04:40 UTC
    Little-endian isn't 2,1,4,3, it's 4,3,2,1.
    >perl -E"say for unpack 'H*', pack 'L<', 0x11223344" 44332211

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found