PHP bin2hex() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The bin2hex() function in PHP converts a string to hexadecimal values. The conversion is done byte-wise with the high-nibble first. Note: It is not for converting strings representing binary digits into hexadecimal. Syntax: bin2hex($string) Parameters: This function accepts a single parameter $string. This is the string that will be converted to hexadecimal values. Return Value: The function returns the hexadecimal value of the string passed in the parameter. Examples: Input : string = "geeks" Output : 6765656b73 Input : string = "1111" Output : 31313131 Explanation: "1111" is converted to its hexadecimal values, it is not treated as a binary string, else the answer would have been F which is not in this case. Below programs illustrate the bin2hex() function in PHP: Program 1: php <?php // PHP program to demonstrate // the bin2hex() function $str = "geeks"; echo bin2hex($str); ?> Output: 6765656b73 Program 2: php <?php // PHP program to demonstrate // the bin2hex() function $str = "1111"; echo bin2hex($str); ?> Output: 31313131 Reference: https://www.php.net/manual/en/function.bin2hex.php Create Quiz Comment S Striver Follow 0 Improve S Striver Follow 0 Improve Article Tags : Misc Web Technologies PHP PHP-string Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like