bin2hex()
The bin2hex()
function converts a string
of characters to a string
of hexadecimal values.
Note: This function does NOT convert strings representing binary digits to hexadecimal values.
Syntax
bin2hex(char_string);
The bin2hex()
function takes only one parameter as a string
, char_string
. The function returns a string
, the hexadecimal value of char_string
.
Example
The following example uses the bin2hex()
function to convert the string
of "PHP"
to hexadecimal values. Then the echo
command prints this value to the console:
<?phpecho bin2hex("PHP");?>
The example will result in the following output:
504850
Codebyte Example
The following example is runnable and creates a new string
type variable, my_string
. Then, the bin2hex()
function converts my_string
into a hexadecimal value, and finally, the echo
command prints this value to the console:
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.