convert a number from base 10 to base 16 in php

To convert a number from base 10 to base 16 (hexadecimal) in PHP, you can use the built-in dechex function. Here's an example:

main.php
$number = 255; // decimal number to convert
$hex = dechex($number); // convert to hexadecimal
echo $hex; // output: ff
119 chars
4 lines

In the example above, we first define a decimal number of 255. We then use the dechex function to convert it to a hexadecimal representation, which is assigned to the $hex variable. Finally, we simply output the hexadecimal number using the echo statement. In this case, the output is ff.

gistlibby LogSnag