<? Php Tutorial
/**
* Convert decimal to binary, octal, or hexadecimal with zero padding before the digits being insufficient *
*
* @ Param array $ datalist input data array (100,123,130)
* @ Param int $ bin conversion can be: 2, 8, 16
* @ Return array returns the data array () and returns the format in which no data is converted.
* @ Copyright chengmo qq: 8292669
*/
Function decto_bin ($ datalist, $ bin)
{
Static $ arr = array (, 'A', 'B', 'C', 'D', 'e ', 'F ');
If (! Is_array ($ datalist) $ datalist = array ($ datalist );
If ($ bin = 10) return $ datalist; // ignore in the same hexadecimal format
$ Bytelen = ceil (16/$ bin); // Obtain the length of a byte in $ bin notation.
$ 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; // The length of less than one byte is automatically increased to 0.
}
$ Aoutchar [] = $ t;
}
Return $ aoutchar;
}