Skip to content

Instantly share code, notes, and snippets.

@pen
Last active July 15, 2016 16:38
Show Gist options
  • Save pen/85eea81a40da03329f8e91bb8c34cd4c to your computer and use it in GitHub Desktop.
Save pen/85eea81a40da03329f8e91bb8c34cd4c to your computer and use it in GitHub Desktop.
#!/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