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

Live Demo

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

The following is the output −

Output

57656c636f6d6521

Let us see another example −

Example

Live Demo

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

The following is the output −

Output

31303131

Updated on: 30-Jul-2019

50 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements