Computer >> Computer tutorials >  >> Programming >> PHP

bin2hex() function in PHP


The bin2hex() function is used to convert primary data to hexadecimal representation

Syntax

bin2hex(str)

Parameters

  • str − The string to be converted.

Return

The bin2hex() function converts a string of ASCII characters to hexadecimal values.

The following is an example −

Example

<?php
   $s = bin2hex("Welcome!");
   echo($s); 
?>

The following is the output −

Output

57656c636f6d6521

Let us see another example −

Example

<?php
   $val = bin2hex("1011");
   echo($val); 
?>

The following is the output −

Output

31303131