PHP hex2bin is an inbuilt function in PHP. It converts a hexadecimal character sequence back to a binary string. However, it does not convert the hexadecimal string to binary number. In this article, we will discuss the PHP hex2bin Function. Also, we will discuss a few examples of using it.
Also, in order to convert a binary string to its corresponding hexadecimal character sequence, you can use the PHP bin2hex Function.
Remember: There is a very big difference between binary data and a string representation of binary.
The function expects only one parameter. The hexadecimal string which needs to be converted to a binary string is the input to the function.
The function returns the corresponding binary string after converting the hexadecimal input. However, on failure, it returns false.
Input: hex2bin('636f6e6361746c79') Output: concatly
For instance, consider the following example of using the function.
<?php $hexadecimalString = '636f6e6361746c79'; $binaryString = hex2bin($hexadecimalString); echo $binaryString; ?>
In the above example, the function converts the input hexadecimal string to a binary string. However, the function cannot convert the string to a binary number.
Vishesh is currently working as a Lead Software Engineer at Naukri.com. He passed out of Delhi College of Engineering in 2016 and likes to play Foosball. He loves traveling and is an exercise freak. His expertise includes Java, PHP, Python, Databases, Design and Architecture.