/* * 函数名:bin2dec * 说明:将2进制字符串数值转换为10进制 */ function bin2dec($bin){ // strrev() 函数反转字符串 $temp = strrev($bin); $result = 0; // strlen() 函数返回字符串的长度 for ($i=0,$len = strlen($temp); $i < $len; $i++) { // pow() 返回2的$i次方的幂 $result += pow(2,$i) * $temp[$i]; } return $result; } $a = '1010'; echo bin2dec($a); 转载于:https://blog.51cto.com/suyanzhu/2300501