hex2bin()

Published May 12, 2023Updated Jun 22, 2023
Contribute to Docs

The hex2bin() function converts a string of hexadecimal values to its binary representation.

Note: This function does NOT convert a hexadecimal number to a binary number. The hex2bin() function is available only in PHP 5.4.0 and later versions.

Syntax

hex2bin(hex_string);

The hex_string parameter represents the string of hexadecimal values to be converted.

Example

The following example uses the hex2bin() function to convert "504850", a string of hexadecimal values, to a string. Then the echo command prints this string to the console:

<?php
echo hex2bin("504850");
?>

The example will result in the following output:

PHP

Codebyte Example

The following example is runnable and uses the hex2bin() function:

Code
Output
Loading...

All contributors

Looking to contribute?

Learn PHP on Codecademy