This article describes the PHP implementation of the 36 binary and 10 binary conversion function. Share to everyone for your reference, as follows:
/** * @desc im: decimal number converted to 36 mechanism * @param (int) $num decimal number * Return: 36 number of binary */function ge T_char ($num) {$num = Intval ($num); if ($num <= 0) return false; $CHARARR = Array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z '); $char = "; do {$key = ($num-1)% 36; $char = $CHARARR [$key]. $char; $num = Floor (($num-$key)/36); } while ($num > 0); return $char;} /** * @desc im: 36 binary number converted to 10 mechanism * @param (string) $char 36 binary number * return: decimal number */function Get_num ($char) {$array =array ("0", " 1 "," 2 "," 3 "," 4 "," 5 "," 6 "," 7 "," 8 "," 9 "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); $len =strlen ($char); for ($i =0; $i < $len; $i + +) {$index =array_search ($char [$i], $array); $sum + = ($index + 1) *pow (approx., $len-$i-1); } return $sum;}
Usage examples:
echo "Get_char:". Get_char (514549). " <br> "; echo" Get_num: ". Get_num (' A0zz ')." <br> ";
I hope this article is helpful to you in PHP programming.