in reply to Printing, analyzing binary

I'm assuming that you've already got the file reading part down, so my code just takes the shortcut of having nice 8-bit representable numbers in __DATA__. Given that intro, here's a pack / unpack approach.

use strict; use warnings; while ( my $num = <DATA> ) { chomp $num; next unless $num; my $bits = unpack "b8", pack "C", $num; my $zeros = $bits =~ tr/0//; my $ones = $bits =~ tr/1//; print <<"OUTPUT"; Decimal: $num \t\tZeros: $zeros Bits: $bits \tOnes: $ones OUTPUT } __DATA__ 1 2 3 4 5 6 7 8 15 31 63 127 255


Dave