PHP Function Reference

PHP dechex() Function



The PHP dechex() function returns a string which is the hexadecimal representation of a decimal number.

The table below shows decimal numbers converted into hexadecimal numbers.

DecimalHexadecimalDecimalHexadecimal
1110a
2211b
3312c
4413d
5514e
6615f
771610
88311f
99255ff

Syntax

dechex(number)

Parameters

number Required. Specify the decimal number to convert.

Return Value

Hexadecimal string representation of a decimal number.

Example:

In the example below, dechex() function returns the hexadecimal string representation of a given decimal number.

<?php
echo "dechex(0) = ".dechex(0)."\n";
echo "dechex(1) = ".dechex(1)."\n";
echo "dechex(15) = ".dechex(15)."\n";
echo "dechex(50) = ".dechex(50)."\n";
echo "dechex(100) = ".dechex(100)."\n";
echo "dechex(500) = ".dechex(500)."\n";
echo "dechex('1000') = ".dechex('1000')."\n";
echo "dechex('54321') = ".dechex('54321')."\n";
?>

The output of the above code will be:

dechex(0) = 0
dechex(1) = 1
dechex(15) = f
dechex(50) = 32
dechex(100) = 64
dechex(500) = 1f4
dechex('1000') = 3e8
dechex('54321') = d431

❮ PHP Math Reference