Skeeve has asked for the wisdom of the Perl Monks concerning the following question:
Hi fellow monks!
I'm searching for a more elegant way to solve this problem. I have a string of 3 byte which contain fields of information packed in bits. These fields have variable length. The bit pattern is: AAABBCCD EEEEFFGH IIJJKLMM.
What I do now is similar to:
So you see, I do:( $a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m )= map { unpack 'C', pack 'b*',$_ } unpack 'A3A2A2A1A4A2A1A1A2A2A1A1A2', unpack 'B*',$x;
Update: I just noticed: My code seemed to work, but didn't work as I expected... I'll update again when I found a working solution :-(
Update #2: Thanks to BrowserUK for finding a working solution!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: unpacking variable length bit fields
by BrowserUk (Patriarch) on Oct 24, 2006 at 12:00 UTC | |
by Skeeve (Parson) on Oct 24, 2006 at 12:18 UTC | |
by BrowserUk (Patriarch) on Oct 24, 2006 at 12:53 UTC |