PHP头条
热点:

php一般字符和16进制字符互相转换的函数


function SingleDecToHex($dec)
{
$tmp="";
$dec=$dec%16;
if($dec<10)
return $tmp.$dec;
$arr=array("a","b","c","d","e","f");
return $tmp.$arr[$dec-10];
}
function SingleHexToDec($hex)
{
$v=Ord($hex);
if(47<$v&&$v<58)
return $v-48;
if(96<$v&&$v<103)
return $v-87;
}
function SetToHexString($str)
{
if(!$str)return false;
$tmp="";
for($i=0;$i{
$ord=Ord($str[$i]);
$tmp.=SingleDecToHex(($ord-$ord%16)/16);
$tmp.=SingleDecToHex($ord%16);
}
return $tmp;
}
function UnsetFromHexString($str)
{
if(!$str)return false;
$tmp="";
for($i=0;$i{
$tmp.=chr(SingleHexToDec(substr($str,$i,1))*16+SingleHexToDec(substr($str,$i+1,1)));
}
return $tmp;
}
?>

SetToHexString("大家好")=


UnsetFromHexString(SetToHexString("大家好"))=

www.phpzy.comtrue/phprm/39292.htmlTechArticlephp一般字符和16进制字符互相转换的函数 function SingleDecToHex($dec) { $tmp=""; $dec=$dec%16; if($dec return $tmp.$dec; $arr=array("a","b","c","d","e","f"); return $tmp.$arr[$dec-10]; } function SingleHexToDec($hex) { $v=Ord(...

相关文章

    暂无相关文章

PHP之友评论

今天推荐