http://www.perlmonks.org?node_id=444071


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