Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Unpacking struct

by Stevie-O (Friar)
on Apr 01, 2005 at 03:09 UTC ( #444071=note: print w/ replies, xml ) Need Help??


in reply to Unpacking struct

pack and unpack can handle very many things, but bitfields are not one of them. You'll have to do some bit-level manipulation to extract the values you want; I would recommend you do this:

$fh->read($buf, 12); # note that your original code used 's', which is signed, # but your struct declaration says unsigned! @var = unpack('S S L L', $buf); my ($var1, $var2) = ($var[0], $var[1]); my $var3 = $var[2] & 0xFFFFFF; my $var4 = $var[2] >> 24; my $var5 = $var[3] & 0x3F; my $var6 = $var[3] >> 6;
--Stevie-O
$"=$,,$_=q>|\p4<6 8p<M/_|<('=> .q>.<4-KI<l|2$<6%s!<qn#F<>;$, .=pack'N*',"@{[unpack'C*',$_] }"for split/</;$_=$,,y[A-Z a-z] {}cd;print lc


Comment on Re: Unpacking struct
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-10-21 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (98 votes), past polls