1234567891011121314151617181920212223242526272829 |
- #!/usr/bin/perl
- use strict;
- use warnings;
-
- my $BUF_LENGTH = 4;
- my $ADR_LENGTH = 8;
-
- binmode STDIN;
-
- my $buff;
- my $addr = 0;
- while (read STDIN, $buff, $BUF_LENGTH) {
- my $len = length $buff;
- my @bytes = unpack "W" x $len, $buff;
- my @b = map { sprintf "%08b", $_ } @bytes;
- my $b = join " ", @b;
- my $h = join "", map {
- $_ = 0x2e if $_ > 0x7f || $_ < 0x20;
- sprintf "%c", $_
- } @bytes;
- my $bw = $BUF_LENGTH * 9 - 1;
- printf
- "%s %s |%s|\n",
- sprintf ("%0${ADR_LENGTH}x", $addr),
- sprintf ("%-${bw}s", $b),
- sprintf ("%-${BUF_LENGTH}s", $h)
- ;
- $addr += $BUF_LENGTH;
- }
|