Last active
July 15, 2016 16:38
-
-
Save pen/85eea81a40da03329f8e91bb8c34cd4c to your computer and use it in GitHub Desktop.
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/env perl | |
use strict; | |
use warnings; | |
sub thconv | |
{ | |
my $n = shift; | |
my ($offset, $divider, $digits) = (1, 0, 0); | |
do { | |
$offset *= 0x100; | |
$divider += $offset; | |
$digits += 2; | |
} while ($n >= $divider); | |
return sprintf("%0*X", $digits, ($n + $offset) % $divider); | |
} | |
{ | |
while (<>) { | |
chomp; | |
my $n = hex($_); | |
printf("%X => %s\n", $n, thconv($n)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment