set S0, "00000000000000000000001001000010" length I0, S0 set I1, 1 set I2, 0 LOOP: dec I0 substr S1, S0, I0, 1 if S1, INC RETURN: mul I1, I1, 2 ge I0, 0, LOOP print I2 print "\n" end INC: add I2, I1 branch RETURN #### rob@kathmandu:~/parrot-0.0.10$ perl assemble.pl count.pasm >count.pbc rob@kathmandu:~/parrot-0.0.10$ ./parrot count.pbc 578 rob@kathmandu:~/parrot-0.0.10$ #### $s0 = "00000000000000000000001001000010"; $i0 = length $s0; $i1 = 1; $i2 = 0; while ( $i0 >= 0 ) { --$i0; $s1 = substr( $s0, $i0, 1 ); if ( $s1 eq '1' ) { $i2 += $i1; } $i1 *= 2; }; print $i2, "\n";