<?xml version="1.0" encoding="windows-1252"?>
<node id="1020203" title="Confusion about code sample in perlfaq4" created="2013-02-22 13:47:11" updated="2013-02-22 13:47:11">
<type id="115">
perlquestion</type>
<author id="1020196">
vr</author>
<data>
<field name="doctext">
&lt;p&gt;I'm confused about code sample from here: &lt;/p&gt;
&lt;p&gt;[doc://perlfaq4#How-do-I-manipulate-arrays-of-bits?]&lt;/p&gt;
&lt;p&gt;They say:&lt;/p&gt;
&lt;blockquote&gt;...given a vector in $vec , you can get those bits into your @ints array:&lt;/blockquote&gt;
&lt;p&gt; and give following code as "fast general algorithm" &lt;/p&gt;
&lt;code&gt;
use integer;
my $bits = unpack "b*", $vec;
push @ints, 0 if $bits =~ s/^(\d)// &amp;&amp; $1;
push @ints, pos $bits while($bits =~ /1/g);
&lt;/code&gt;
&lt;p&gt;What are they trying to do with two lines starting with push operators? Don't they want to get a list "e.g. ( 1, 0, 0, 1, 1, 0 ... )" as stated in the beginning of that section, i.e. do reverse conversion? They can't do it with this code, do they?&lt;/p&gt;
</field>
</data>
</node>
