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.php119 chars4 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