$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";