in reply to Re: Printing, analyzing binary
in thread Printing, analyzing binary
Something I have encountered during my research is the "vec" function (built in) and the Bit::Vector module. Am I correct to assume that both of these provide some level of functionality meant to easily manage/manipulate a series of bits (or boolean values) that are contained inside of an array? TIAmy $buffer; open INF, $srcfile or die "\nCan't open $srcfile for reading: $!\n"; binmode INF; while (read (INF, $buffer, 1)) { # to string my $bits = unpack("b*", $buffer); # count total length, though = # bits my $tot = length($bits); # count 1s my $num1s = 0; while ($bits =~ /1/g) { $num1s++ }; # count 0s my $num0s = 0; while ($bits =~ /0/g) { $num0s++ }; # print info print "$bits\n"; print "$num1s 1's; $num0s 0's; $tot total length\n"; }
|
|---|