PHP bin2hex() Function

You are Here:

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
strRequiredSpecifies the string to be converted.

Return Value

ValueExplanation
NumberReturns 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; ?>

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on PHP with examples for quick and easy learning.

We are working to cover every Single Concept in PHP.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author