Skip to content

Instantly share code, notes, and snippets.

@hogem
Created May 17, 2012 04:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hogem/2716377 to your computer and use it in GitHub Desktop.
Save hogem/2716377 to your computer and use it in GitHub Desktop.
convert ascii to binary, or binary to ascii
#!/usr/bin/perl
use strict;
use warnings;
## one liner
# perl -ne 'print unpack("H*", $_)' < ascii > binary
# perl -ne 'print pack("H*", $_)' < binary > ascii
my $mode = shift || help();
if (lc $mode eq "a2b") {
while (<>) {
print unpack("H*", $_);
}
}
elsif (lc $mode eq "b2a") {
while (<>) {
print pack("H*", $_);
}
}
else {
help();
}
sub help {
die
"Usage:
ascii to binary: $0 a2b < ascii > binary
binary to ascii: $0 b2a < binary > ascii\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment