in reply to perl bitology - breaking into bytes
Not very efficient though.# Warning: Untested code ahead! # Enter at your own risk! read($file, $buf, 128); $bits= unpack("B*",$buf); # or "b*" depending on bit order do { if ($r= read($file, $byte, 1)) { $newbits=unpack("B*",$byte); # or "b*" depending on bit order $bits.=$newbits; } print "match!\n" if $bits=~ /^.{0,7}.{9}0{6}.{35}1{51}.{27}/; # ^ ^ ^ ^ ^ ^ # possible offset. 0-7 Bit ---/ | | | | | # match exactly 9 bits -------------/ | | | | # match Bits 9-14 as 0 -----------------/ | | | # match 35 Bits to advance to bit 50 -------/ | | # Bits 50-100 (51 Bits) must match 1 ------------/ | # to match the last 27 bits of your frame-------------/ $bits= substr($bits,8); } while ($r);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: perl bitology - breaking into bytes
by spurperl (Priest) on Oct 20, 2003 at 11:44 UTC |