Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The particular problem I'm having at the moment is unpacking a C struct like this:
struct { unsigned long var1:16, var2:16; unsigned long var3:24, var4:8; unsigned long var5:6, var6:26; };
The first 2, I got (I think), the second 2 I THOUGHT I got, but was wrong.. the last 2... well, frankly I'm just not too sure. Here's what I tried:
$fh->read($buf, 12); @var = unpack("s s C3 C b6 b26", $buf);
Now, $var[0] and $var[1] end up as 2 byte shorts (as I expected), $var[2] ends up as 1 byte, not the 3 bytes I was expecting... it looks like the 2nd and 3rd bytes are put into $var[3] and $var[4]... which of course throws the rest off track.
How do I grab 3 bytes and put that into a single var, not split into 3 separate vars?
With regards to the "b6" and "b26"... well... I don't really want the value returned as binary data... I just want a 6 bit integer and a 26 bit integer respectively. How do I do that?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unpacking struct
by Zaxo (Archbishop) on Apr 01, 2005 at 03:26 UTC | |
|
Re: Unpacking struct
by Stevie-O (Friar) on Apr 01, 2005 at 03:09 UTC | |
|
Re: Unpacking struct
by Random_Walk (Prior) on Apr 01, 2005 at 10:04 UTC | |
|
Re: Unpacking struct
by ikegami (Patriarch) on Apr 01, 2005 at 02:46 UTC |