Current Location: Home> Function Categories> bin2hex

bin2hex

Convert binary data to hexadecimal representation
Name:bin2hex
Category:String
Programming Language:php
One-line Description:Converts the string of ASCII characters to hexadecimal values.

Definition and usage

bin2hex() function converts the string of ASCII characters into hexadecimal values. Strings can be converted back by using the pack() function.

Example

Example 1

Convert "Shanghai" to hexadecimal value:

 <?php
$str = bin2hex ( "Shanghai" ) ;
echo ( $str ) ;
?>

Try it yourself

Example 2

Convert a string value from binary to hexadecimal and then convert it back:

 <?php
$str = "Shanghai" ;
echo bin2hex ( $str ) . "<br>" ;
echo pack ( "H*" , bin2hex ( $str ) ) . "<br>" ;
?>

Try it yourself

grammar

 bin2hex ( string )
parameter describe
string Required. The string to be converted.
Similar Functions
Popular Articles