in reply to Unpacking variable length bit fields
Assuming your bitfields are all multiples of 8, then using unpack's length/type nomenclature will work.
You'll need to use the correct variations of 'c' or 'C' (probably the latter) and b/B (which will depend upon the endianess of the originating hardware. I've used a mixture here to demonstrate the affect of some of the combinations.$bitstream = "\x18\xf0\xff\x0f\x10\xaa\x55\x20\xde\xad\xbe\xef";; ( $f1, $f2, $f3 ) = unpack 'C/b C/b c/B', $bitstream;; print for $f1, $f2, $f3;; 000011111111111111110000 0101010110101010 11011110101011011011111011101111
Note also that the output is ascii-ised binary. That is, each bit of the input is translated to a byte containing ascii '0' or ascii '1'.
Other variations are possible. For example, you might want to retain the bits as binary encoded fields and then manipulate them with vec. But you'd need to explain more about what they are.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unpacking variable length bit fields
by puterboy (Scribe) on Jun 19, 2012 at 04:15 UTC | |
by BrowserUk (Patriarch) on Jun 19, 2012 at 05:30 UTC | |
|
Re^2: Unpacking variable length bit fields
by puterboy (Scribe) on Jun 18, 2012 at 22:58 UTC |