Created
May 17, 2012 04:32
-
-
Save hogem/2716377 to your computer and use it in GitHub Desktop.
convert ascii to binary, or binary to ascii
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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