PHP bin2hex() Function

Last Updated:

PHP bin2hex()

The bin2hex() function converts a string of binary characters to hexadecimal values.

Example

PHP Compiler
<?php echo bin2hex("1010"); ?>

Syntax

bin2hex(str)

Parameter Values

ValueTypeExplanation
str Required Specifies the string to be converted.

Return Value

ValueExplanation
Number Returns an ASCII string containing the hexadecimal representation of str.

More Example

In the following example, we will use the hex2bin() and pack() functions to convert the hexadecimal value back to the binary value.

Example

PHP Compiler
<?php $bin = "Wikimass.com"; echo "<br>convert binary to hexadecimal"; $hex = bin2hex($bin); echo "<br> hexadecimal = " .$hex; echo "<br>convert hexadecimal back to binary"; $bin = hex2bin($hex); echo "<br> binary = " .$bin; echo "<br>convert hexadecimal back to binary"; $bin1 = pack("H*", $hex); echo "<br> binary = " .$bin1; ?>

Share this Page

Meet the Author