Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: sequence of positions to binary sequence

by gone2015 (Deacon)
on Apr 16, 2009 at 08:24 UTC ( [id://757886]=note: print w/replies, xml ) Need Help??


in reply to sequence of positions to binary sequence

my @pos = (2,4,6,9) ; my $bits = '' ; foreach (@pos) { vec($bits, $_, 1) = 1 ; } ; ($bits = unpack('b*', $bits)) =~ s/0+$// ; my @bits = split(//, $bits) ; print "(", join(',', @bits), ")\n" ;
...when dealing with bit vectors vec is your friend, as are unpack/pack b/B and (occasionally) reverse.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-26 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found