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
  • Calculate the length of the first substring in which all characters in the string exist in the specified character set strspn

    strspn

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

    str_word_count

    Returninformationabo
  • Convert the first byte of the string to a value between 0-255 ord

    ord

    Convertthefirstbyteo
  • Convert binary data to hexadecimal representation bin2hex

    bin2hex

    Convertbinarydatatoh
  • Output formatted string printf

    printf

    Outputformattedstrin
  • Alias ​​of rtrim chop

    chop

    Alias​​ofrtrim
  • Binary safe case-insensitive string comparison strcasecmp

    strcasecmp

    Binarysafecase-insen
  • Returns information about the characters used in the string - counts the number of times each byte value (0..255) occurs in a string count_chars

    count_chars

    Returnsinformationab
Popular Articles