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
  • Find the first occurrence of a string strstr

    strstr

    Findthefirstoccurren
  • Calculate the md5 hash value of a string md5

    md5

    Calculatethemd5hashv
  • Binary safe string comparison strcmp

    strcmp

    Binarysafestringcomp
  • Return information about the words used in the string str_word_count

    str_word_count

    Returninformationabo
  • Calculate the md5 hash value of a given file md5_file

    md5_file

    Calculatethemd5hashv
  • Convert binary data to hexadecimal representation bin2hex

    bin2hex

    Convertbinarydatatoh
  • Find the last occurrence of a specified character in a string strrchr

    strrchr

    Findthelastoccurrenc
  • Use one string to split another string into an array explode

    explode

    Useonestringtosplita