How to convert binary to hex string by php
This article is about how php converts binaries to hex strings. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Php will binary to hex string method: 1, use bindec () and dechex () function, syntax "dechex (bindec ($unm))". 2. Use the base_convert () function with the syntax "base_convert ($unm, 2,16)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php converts binary to hex (hexadecimal) string
Method 1: use the bindec () and dechex () functions-- decimal-- as intermediate quantities
Output result:
1e
Bindec () converts a binary number to a decimal number.
The dechex () function converts decimal numbers to hexadecimal numbers.
Method 2: use the base_convert () function
Output result:
1e
The base_convert (number, primitive, base to convert) function converts numbers between arbitrary bases.
Thank you for reading! This is the end of the article on "how php converts binary to hex string". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!