in reply to Run length encode a bit vector
use strict; use warnings; my $bytes = pack 'N', 0x01020304; my $bits = unpack('B32', $bytes); my @counts; while ($bits =~ /(0+|1+)/g) { push @counts, length($1) * (substr($1, 0, 1) == 1 ? 1 : -1); } print "$bits\n@counts";
Output:
00000001000000100000001100000100 -7 1 -6 1 -7 2 -5 1 -2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Run length encode a bit vector
by ikegami (Patriarch) on Jan 05, 2012 at 19:28 UTC | |
by TJPride (Pilgrim) on Jan 05, 2012 at 20:42 UTC | |
by ikegami (Patriarch) on Jan 05, 2012 at 20:59 UTC |