Example 1 — Convert decimal numbers to hex
Start with a few simple numbers and see what hex strings come back.
<?php
echo dechex(255) . PHP_EOL;
echo dechex(10) . PHP_EOL;
echo dechex(4095) . PHP_EOL; How It Works
- dechex(255) converts 255 into base 16, which is "ff".
- dechex(10) gives "a" because a single hex digit can go up to f (15).
- dechex(4095) gives "fff" since 4095 is 16 x 16 x 16 minus 1.
- PHP_EOL adds a new line after each result so the output is easy to read.

