#!/usr/bin/perl use strict; use warnings; # show_binary # This script takes one or more filenames as command-line arguments # and outputs (to STDOUT) the contents of those files in base 2 numbers. # If no arguments are given, it reads from STDIN. # Cameron Hayne (macdev@hayne.net) December 2003 my $num_per_line = 1; # number of bytes to output before a carriage return my $show_line_count = 1; my $count = 0; print $count, "\t" if $show_line_count; while (<>) { foreach my $byte (split(//)) { my $str = unpack("B8", $byte); print $str; if (++$count % $num_per_line == 0) { print "\n"; print $count/$num_per_line, "\t" if $show_line_count; } } } print "\n";