note 93257 deleted from function.base-convert by danbrown
| From: | danbrown@php.net | Date: | Mon, 31 Aug 2009 03:47:53 +0000 |
| Subject: | note 93257 deleted from function.base-convert by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160071@lists.php.net to get a copy of this message | ||
Note Submitter: Adrien Gibrat
----
just my 2 coins
function decbase ( $integer, $base =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ) {
$length = strlen( $base );
$out = '';
while ( $integer > $length - 1 ) {
$out = $base[fmod( $integer, $length )] . $out;
$integer = floor( $integer / $length );
}
return $base[$integer] . $out;
}
function basedec ( $string, $base =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ) {
$length = strlen( $base );
$size = strlen( $string ) - 1;
$string = str_split( $string );
$out = strpos( $base, array_pop( $string ) );
foreach ( $string as $i => $char )
$out += strpos( $base, $char ) * pow( $length, $size - $i );
return $out;
}