加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何将8位二进制数据转换为十六进制

发布时间:2020-12-13 16:55:38 所属栏目:PHP教程 来源:网络整理
导读:print_r(bin2hex("22222111"));echo '/br';print_r(bindec("22222111")); 结果 131313131313131 255 I want a hexadecimal 16 byte value to do aes encryption.How is the conversion from binary to hex happening in php.I am getting incorrect value us
print_r(bin2hex("22222111"));
echo '</br>';
print_r(bindec("22222111"));

结果

> 131313131313131
> 255

I want a hexadecimal 16 byte value to do aes encryption.How is the conversion from binary to hex happening in php.I am getting incorrect value using the function.Also when i convert an array of hexadecimal values to string the byte length changes

解决方法

你得到了正确的结果,这不是你想要的. bin2hex()返回十六进制表示的ASCII字符串.手册中的引用:

Returns an ASCII string containing the hexadecimal representation of str.

所以如果你想要十六进制数,你可以使用这个:

print_r(dechex(bindec("22222111")));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读