Created
January 27, 2017 08:35
-
-
Save lrhn/860828e95c538c1e537ca74999f7421b to your computer and use it in GitHub Desktop.
ASCII helper script - converts arguments to ASCII codes
This file contains hidden or 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 | |
my $format = "%2.2X"; | |
if ($ARGV[0] eq "-l") { | |
$format = "%2.2x"; | |
shift @ARGV; | |
} | |
if ($#ARGV >= 0) { | |
my @hex = (); | |
for $a (@ARGV) { | |
for $c ( split("", $a) ) { | |
my $h = sprintf($format, ord($c)); | |
push @hex, $h; | |
printf("$c : 0x$h \\x$h\n"); | |
} | |
} | |
print(join ", ", (map {"0x$_"} @hex)); | |
print("\n"); | |
my $d = '"'; | |
$d = "'" if ($#hex == 0); | |
print($d); | |
print(join "", (map {"\\x$_"} @hex)); | |
print("$d\n"); | |
} else { | |
print(" 0123456789abcdef\n"); | |
print("0x20 !\"#\$%&'()*+,-./\n"); | |
print("0x30 0123456789:;<=>?\n"); | |
print("0x40 \@ABCDEFGHIJKLMNO\n"); | |
print("0x50 PQRSTUVWXYZ[\\]^_\n"); | |
print("0x60 `abcdefghijklmno\n"); | |
print("0x70 pqrstuvwxyz{|}~\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment