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
In reply to Re: Printing, analyzing binary
by davido
in thread Printing, analyzing binary
by perlfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |