bin2hex
Convert binary data to hexadecimal representation
bin2hex()
function converts the string of ASCII characters into hexadecimal values. Strings can be converted back by using the pack()
function.
Convert "Shanghai" to hexadecimal value:
<?php $str = bin2hex ( "Shanghai" ) ; echo ( $str ) ; ?>
Try it yourself
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
bin2hex ( string )
parameter | describe |
---|---|
string | Required. The string to be converted. |