Skip to content

Instantly share code, notes, and snippets.

@Andrielson
Created September 2, 2020 15:15
Show Gist options
  • Save Andrielson/6b580bce4dbc39060cda33eab79bc77f to your computer and use it in GitHub Desktop.
Save Andrielson/6b580bce4dbc39060cda33eab79bc77f to your computer and use it in GitHub Desktop.
PHP base64int
<?php
define('ALFABETO', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
function tetrasexagesimal(int $numero): string {
$retorno = "";
while ($numero >= 0) {
if ($numero === 0) {
$retorno = "A{$retorno}";
break;
}
$digito = $numero % 64;
$retorno = ALFABETO[$digito] . $retorno;
$numero = intdiv($numero, 64);
if ($numero === 0) {
break;
}
}
return $retorno;
}
echo tetrasexagesimal(2147483647) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment