php method to convert binary to hexadecimal: 1. Create a PHP sample file; 2. Use the bin2hex() function to convert a string of ASCII characters into a hexadecimal value.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How to convert binary to hexadecimal in php System?
Binary to hexadecimal
Function: bin2hex(string $str);
@param $str will be converted A string of ASCII characters.
@return Returns the hexadecimal value of the converted string.
Function description:
The bin2hex() function converts a string of ASCII characters into a hexadecimal value. Strings can be converted back using the pack() function.
Bin2hex () Function to convert the byte method.
Example:
(1)bin2hex() converts 'chengdu' to hexadecimal value:
<?php $str = bin2hex('chengdu'); echo $str;
The above program statement will output: 6368656e676475
(2) Convert a string value from binary to hexadecimal, and then convert it back:
<?php $str = 'chengdu'; echo bin2hex($str) . "<br/>"; echo pack("H*", bin2hex($str)) . "<br/>";
The above program statements are output in sequence: 6368656e676475, chengdu
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert binary to hexadecimal in php. For more information, please follow other related articles on the PHP Chinese website!