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

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;
$"=$,,$_=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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://444071]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-07-20 16:40 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (308 votes). Check out past polls.