function IntToBaseStr(n: longword; const b: cardinal): string;
const
digits = '0123456789abcdefghijklmnopqrstuvwxyz';
var
remainder: longword;
begin
Result := '';
repeat
DivMod(n, b, n, remainder);
result := digits[remainder + 1] + result;
until n = 0;
end;
subint_to_base_str{
my ($n, $b) = @_;
my $digits = '0123456789abcdefghijklmnopqrstuvwxyz';
my ($s, $q, $remainder) = ('');
return'0'if $n == 0;
use integer;
while ($n) {
($n, $remainder) = ($n / $b, $n % $b),
$s = substr($digits, $remainder, 1) . $s;
}
return $s
}
A translation of the python implementation. Perl doesn't have a divmod function so we roll out own by calculating the quotient with integer division and the remainder with modulo.
defint_to_base_str(n, b):
digits = '0123456789abcdefghijklmnopqrstuvwxyz'
s = ''if n == 0: return'0'while n:
n, remainder = divmod(n, b)
s = digits[remainder] + s
return s
function IntToBaseStr(n: longword; const b: cardinal): string;
const
digits = '0123456789abcdefghijklmnopqrstuvwxyz';
var
remainder: longword;
begin
Result := '';
repeat
DivMod(n, b, n, remainder);
result := digits[remainder + 1] + result;
until n = 0;
end;
def int_to_base_str(n, b):
digits = '0123456789abcdefghijklmnopqrstuvwxyz'
s = ''
if n == 0: return '0'
while n:
n, remainder = divmod(n, b)
s = digits[remainder] + s
return s