Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Run length encode a bit vector

by BrowserUk (Patriarch)
on Jan 05, 2012 at 16:02 UTC ( [id://946431]=note: print w/replies, xml ) Need Help??


in reply to Run length encode a bit vector

sub rle { my $rVec = shift; my $bits = length( $$rVec ) *8; my $i = vec( $$rVec, 0, 1 ); my @counts; my $p = 1; while( $p < $bits ) { push @counts, 1; ++$counts[ -1 ] while $p < $bits and vec( $$rVec, $p++, 1 ) == + $i; $counts[ -1 ] *= -1 if $i; $i ^= 1; } return \@counts; } ;; $v = pack 'N', 0x01020304;; print unpack 'b*', $v;; 10000000010000001100000000100000 print @{ rle( \$v ) };; -1 8 -1 6 -2 8 -1 5

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://946431]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (9)
As of 2024-04-19 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found