Created
March 8, 2010 14:46
-
-
Save kamipo/325213 to your computer and use it in GitHub Desktop.
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 | |
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