ASCII To Hexadecimal
This algorithm converts ASCII code to hexadecimal numbers.
function ASCIIToHexadecimal($str)
{
$hex = "";
$strLen = strLen($str);
for ($i = 0; $i < $strLen; $i++)
{
$chex = DecimalToHexadecimal(ord($str[$i]));
if (strlen($chex) == 1)
$chex = substr_replace($chex, "0", 0, 0);
$hex .= $chex;
}
return $hex;
}
function DecimalToHexadecimal($dec)
{
if ($dec < 1) return "0";
$hex = $dec;
$hexStr = "";
while ($dec > 0)
{
$hex = $dec % 16;
if ($hex < 10)
$hexStr = substr_replace($hexStr, chr($hex + 48), 0, 0);
else
$hexStr = substr_replace($hexStr, chr($hex + 55), 0, 0);
$dec = floor($dec / 16);
}
return $hexStr;
}
Example
$data = "Programming Algorithms";
$value = ASCIIToHexadecimal($data);
Output
50726F6772616D6D696E6720416C676F726974686D73