This function takes a decimal value integer and returns a string of its hexadecimal representation. A hex number ranges 0-9 then A-F where A = 10, B = 11, etc.

If you pass it a float, it will be truncated (not rounded). Passing in a negative number may return unexpected results.

The function hexdec() does the opposite. Give it the hex form and get the decimal.

$hex = dechex(4);   // 4
$hex = dechex(4.8); // 4
$hex = dechex(17);  // 11
$hex = dechex(27);  // 1b
 
$hex = dechex(-4);  // fffffffc
 
// strings will be converted to integer
$hex = dechex('Q');   // 0
$hex = dechex('27Q'); // 1b

When converting decimal to hex, if the value is out of range it will be truncated at that spot. This is case insensitive.

$dec = hexdec('a29e');   // 41630
$dec = hexdec('A29E');   // 41630
$dec = hexdec('a29E');   // 41630
$dec = hexdec('a29ex2'); // 41630