Skip to content

Instantly share code, notes, and snippets.

@flxxyz
Last active July 13, 2021 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flxxyz/820749e3d9c66c1ba06c4e2596995ee3 to your computer and use it in GitHub Desktop.
Save flxxyz/820749e3d9c66c1ba06c4e2596995ee3 to your computer and use it in GitHub Desktop.
自定义多进制很骚
<?php
/**
* 自定义多进制
* @param $str 自定义的多进制字符串
* @param $num 十进制数字
* @return string
* @author alexander_phper
* @link https://blog.csdn.net/alexander_phper/article/details/51363491
*/
function xbin($str, $num){
$num = floatval($num);
$x = strlen($str);
$arr = str_split($str);
$digit = fmod($num, $x);
$xbin = isset($arr[$digit]) ? $arr[$digit] : null;
$pre_digit = floor($num / $x);
if($pre_digit >= 1){
$pre_digit = xbin($str, $pre_digit);
return $pre_digit.$xbin;
}
return $xbin;
}
@cnzzr
Copy link

cnzzr commented Jul 13, 2021

递归调用的方法名没有修改过来,xbin => xdec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment