unpack() - how to handle bitfields??
| From: | Tim Molendijk | Date: | Sun, 29 Dec 2002 01:14:45 +0000 |
| Subject: | unpack() - how to handle bitfields?? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-129556@lists.php.net to get a copy of this message | ||
Hi all,
I'm wrestling with this problem for a while now. I want to read a binary
file (created by C software) using PHP. I know of unpack(). But the C struct
that is stored in the binary file contains variables with bitfields:
struct some_struct {
char val_a : 2
int val_b : 7
}
Such a construct means that val_a is char with a bitfield of 2 and therefore
can contain values between 0 (00 binary) and 3 (11 binary). val_b is an
integer with a range of 0 (0000000) to 127 (1111111).
Now the problem is: how on earth do I handle those values with PHP's
unpack()?!? I've tried a lot of syntaxes but none of them seem to work. Can
someone please shortcut whether it is possible or not and if yes, *how*?
Thanks in advance,
Tim