Skip to content

Instantly share code, notes, and snippets.

@kamipo
Created March 8, 2010 14:46
Show Gist options
  • Save kamipo/325213 to your computer and use it in GitHub Desktop.
Save kamipo/325213 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
BEGIN {
my @table = (0 .. 9, 'A' .. 'Z', 'a' .. 'z', '_', '-');
use constant NUM64 => \@table;
use constant DIGIT => 6;
use constant MASK => (2**DIGIT - 1);
}
use Data::Dumper;
sub print_r {
local $Data::Dumper::Sortkeys = 1;
print Dumper @_;
}
print_r(NUM64) if 0;
sub conv10to64 {
my $d = shift;
my $result;
while ($d) {
$result = NUM64->[$d & MASK] . $result;
$d >>= DIGIT;
}
return $result;
}
is(conv10to64(66), '12');
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment