Home >Backend Development >PHP Tutorial >求段php crc 校验码的计算形式(PHP异或)

求段php crc 校验码的计算形式(PHP异或)

WBOY
WBOYOriginal
2016-06-13 12:07:461497browse

求段php crc 校验码的计算方式(PHP异或)

比如我有段字符串"139c",用计算器计算校验码, 把  13^9c=  复制到计算器用16进制计算得出 8F 是正确的

用PHP计算:

<br />echo dechex(0x13^0x9c); //结果为 8f,正确<br /><br />echo "<hr>";<br /><br />$s1 = '0x13';<br />$s2 = '0x9c';<br />echo dechex($s1^$s2);//结果为 0, 错误<br /><br />echo "<hr>";<br /><br />$s3 = '13';<br />$s4 = '9c';<br />echo dechex($s3^$s4); //结果为 0 , 错误<br />



把值赋到变量里计算结果跟直接写结果不一样,很纳闷。。。请各位指点一下,或给出个可用的计算函数
------解决思路----------------------
$s1 = 0x13;<br />$s2 = 0x9c;<br />echo dechex($s1^$s2);<br />
8f 
没有问题
------解决思路----------------------
<br />$s1 = hexdec('0x13');<br />$s2 = hexdec('0x9c');<br />echo dechex($s1^$s2); // 8F<br /><br />$s3 = hexdec('13');<br />$s4 = hexdec('9c');<br />echo dechex($s3^$s4); // 8F<br />

这样就正常了。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn