Created
September 2, 2020 15:15
-
-
Save Andrielson/6b580bce4dbc39060cda33eab79bc77f to your computer and use it in GitHub Desktop.
PHP base64int
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
<?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