Thursday, September 4, 2025
HomeLanguagesPHP bin2hex() Function

PHP bin2hex() Function


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 = "neveropen"
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 program to demonstrate
// the bin2hex() function 
  
$str = "neveropen";
  
echo bin2hex($str);
  
?>


Output:

6765656b73

Program 2:




<?php
// PHP program to demonstrate 
// the bin2hex() function 
  
$str = "1111";
  
echo bin2hex($str);
  
?>


Output:

31313131 

Reference:
http://php.net/manual/en/function.bin2hex.php

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS