Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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

Comment on Re: Unpacking struct
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2015-03-28 11:37 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (625 votes), past polls