标签:16 hex byte2 byte1 异或 result str PHP
公司需要烦恼呀,下面演示 8686808905171750601011 异或效验,判断最终程序是否效验正确地址:http://www.metools.info/code/c48.html
注:简单来说就是,有abc三个数,a异或b异或c = d
首先把 8686808905171750601011 拆分成 86 86 80 89 05 17 17 50 60 10 11
$str = '8686808905171750601011'; $hex = []; for($i = 0;$i < strlen($str); $i++ ) { if(($i % 2) == 0) { $hex[] = strtoupper(substr($str,$i,2)); } }
然后编写两个函数
/** * # +======================================================================== * # | - @name hex数据BBC异或校验(两两比较) * # | - @author cq <just_leaf@foxmail.com> * # | - @copyright zmtek 2020-11-24 * # +------------------------------------------------------------------------ * # | - 返回结果 * # +======================================================================== */ function hexOr($byte1, $byte2) { $result = ''; $byte1 = str_pad(base_convert($byte1, 16, 2), '8', '0', STR_PAD_LEFT); $byte2 = str_pad(base_convert($byte2, 16, 2), '8', '0', STR_PAD_LEFT); $len1 = strlen($byte1); for ($i = 0; $i < $len1 ; $i++) { $result .= $byte1[$i] == $byte2[$i] ? '0' : '1'; } return strtoupper(base_convert($result, 2, 16)); } /** * # +======================================================================== * # | - @name hex数据BBC异或校验(多个hex数据进行校验) * # | - @author cq <just_leaf@foxmail.com> * # | - @copyright zmtek 2020-11-24 * # +------------------------------------------------------------------------ * # | - 返回结果 * # +======================================================================== */ function hexOrArr($data) { $result = $data[0]; for ($i = 0; $i < count($data) - 1; $i++) { $result = hexOr($result, $data[$i + 1]); } return $result; }
开始调用
echo hexOrArr($hex);
得到的结果是:3D
标签:16,hex,byte2,byte1,异或,result,str,PHP 来源: https://www.cnblogs.com/leaf-cq/p/16179564.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。