bd.pl 657B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. my $BUF_LENGTH = 4;
  5. my $ADR_LENGTH = 8;
  6. binmode STDIN;
  7. my $buff;
  8. my $addr = 0;
  9. while (read STDIN, $buff, $BUF_LENGTH) {
  10. my $len = length $buff;
  11. my @bytes = unpack "W" x $len, $buff;
  12. my @b = map { sprintf "%08b", $_ } @bytes;
  13. my $b = join " ", @b;
  14. my $h = join "", map {
  15. $_ = 0x2e if $_ > 0x7f || $_ < 0x20;
  16. sprintf "%c", $_
  17. } @bytes;
  18. my $bw = $BUF_LENGTH * 9 - 1;
  19. printf
  20. "%s %s |%s|\n",
  21. sprintf ("%0${ADR_LENGTH}x", $addr),
  22. sprintf ("%-${bw}s", $b),
  23. sprintf ("%-${BUF_LENGTH}s", $h)
  24. ;
  25. $addr += $BUF_LENGTH;
  26. }