首页 >后端开发 >php教程 >php一般字符和16进制字符互相转换的函数_PHP教程

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-07-13 17:24:051030浏览


function SingleDecToHex($dec)
{
$tmp="";
$dec=$dec%16;
if($decreturn $tmp.$dec;
$arr=array("a","b","c","d","e","f");
return $tmp.$arr[$dec-10];
}
function SingleHexToDec($hex)
{
$v=Ord($hex);
if(47return $v-48;
if(96return $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("大家好")==SetToHexString("大家好")?>


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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/532175.htmlTechArticlefunction 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) { $...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn