Why we use bin2hex() Function in PHP

Why we use bin2hex() Function in PHP

The bin2hex() function is used to converts a string to hexadecimal. This conversion is performed byte-wise and with the high-nibble first.

Note: It is not for converting strings representing binary digits into hexadecimal.

Syntax:

bin2hex($my_string)

What are the Parameters?

The bin2hex($my_string) function accepts a single parameter $my_string. This is the string that will be converted to hexadecimal values.

What are Return Values?

The bin2hex($my_string) function returns the hexadecimal value of the string passed in the parameter.

Examples:

Input : string = ” t4tutorials”

Output : 74347475746f7269616c73

Input : string = ” 444″

Output : 343434

Let’s see some PHP programs that illustrate the bin2hex() function.

Example 1: PHP bin2hex() function

Output

74347475746f7269616c73

Example 2: PHP bin2hex() function

Output

343434

Add a Comment