/**
* decimal-to-binary, octal, hex-less digits 0 *
*
* @param array $datalist incoming data array (100,123,130)
* The binary @param int $bin conversion can be: 2,8,16
* @return Array return data array () returns no data conversion format
* @copyright Chengmo qq:8292669
*/
function Decto_bin ($datalist, $bin)
{
Static $arr =array (0,1,2,3,4,5,6,7,8,9, ' A ', ' B ', ' C ', ' d ', ' e ', ' f ');
if (!is_array ($datalist)) $datalist =array ($datalist);
if ($bin ==10) return $datalist; Same binary Ignore
$bytelen =ceil (16/$bin); Get the length of a byte if it is a $bin binary
$aoutchar =array ();
foreach ($datalist as $num)
{
$t = "";
$num =intval ($num);
if ($num ===0) continue;
while ($num >0)
{
$t = $arr [$num% $bin]. $t;
$num =floor ($num/$bin);
}
$tlen =strlen ($t);
if ($tlen% $bytelen!=0)
{
$pad _len= $bytelen-$tlen% $bytelen;
$t =str_pad ("", $pad _len, "0", str_pad_left). $t; Less than one byte length, auto front add 0
}
$aoutchar []= $t;
}
return $aoutchar;
}
http://www.bkjia.com/PHPjc/444835.html www.bkjia.com true http://www.bkjia.com/PHPjc/444835.html techarticle PHP Tutorial/** * Decimal to Binary, octal, hex less than 0 * * * @param array $datalist incoming data array (100,123,130) * @param int $bin Conversion of the binary ...