Decimal To Hexadecimal

This algorithm converts decimal numbers to hexadecimal numbers.



									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 = 484879;
$value = DecimalToHexadecimal($data);
								


Output

									7660F