您的位置 首页 技术专栏

php怎么将二进制转hex字符串

24小时课堂在线收录php怎么将二进制转hex字符串,php将二进制转hex字符串的方法:1、使用bindec()和dechex()函数,语法“dechex(bindec($unm))”。2、使…感谢您关注php怎么将二进制转hex字符串。

php将二进制转hex字符串的方法:1、使用bindec()和dechex()函数,语法“dechex(bindec($unm))”。2、使用base_convert()函数,语法“base_convert($unm, 2, 16)”。

本教程操作环境:windows7系统、PHP7.1版,DELL G3电脑

php将二进制转hex(十六进制)字符串

方法1:使用bindec()和dechex()函数–十进制做中间量

<?php$a="11110";$b=bindec($a);$c=dechex($b);echo $c;?>

输出结果:

1e

bindec()可把二进制数转换为十进制数。

dechex() 函数可把十进制数转换为十六进制数。

方法2:使用base_convert()函数

<?php$a="11110";echo base_convert($a, 2, 16);?>

输出结果:

1e

base_convert(number,原进制,要转换的进制)函数在任意进制之间转换数字。

以上就是php怎么将二进制转hex字符串的详细内容,更多请关注24小时课堂在线其它相关文章!

本文来自网络,不代表24小时课堂在线立场,转载请注明出处:https://www.24ketang.cn/96340.html

为您推荐

返回顶部