in reply to binary string
use strict; use warnings; my $cnt = 0; for my $v (0 .. 127) { if ($v < 64) { $cnt++; } else { my $bin = sprintf '%08b', $v; my @pairs = $bin =~ /\d\d/g; $cnt++ if (grep {$_ eq '00'} @pairs); } } print "$cnt\n"; __END__ 101
Update: The grep performs the logical "or" check of your 4 bit pairs (to "00"). I changed your sprintf format spec to always print exactly 8 characters.
|
|---|