php method to convert binary to hex string: 1. Use the bindec() and dechex() functions, the syntax is "dechex(bindec($unm))". 2. Use the base_convert() function, the syntax is "base_convert($unm, 2, 16)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php will convert binary hex (hexadecimal) string
Method 1: Use the bindec() and dechex() functions--decimal to make the intermediate amount
<?php $a="11110"; $b=bindec($a); $c=dechex($b); echo $c; ?>
Output result:
1e
bindec() can convert binary numbers to decimal numbers.
dechex() function can convert decimal numbers to hexadecimal numbers.
Method 2: Use base_convert() function
<?php $a="11110"; echo base_convert($a, 2, 16); ?>
Output result:
1e
base_convert(number, original base, to be converted base)
function converts numbers between any bases.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert binary to hex string in php. For more information, please follow other related articles on the PHP Chinese website!