PHP dechex() Function

In this chapter you will learn:

  1. Definition for PHP dechex() Function
  2. Syntax for PHP dechex() Function
  3. Parameter for PHP dechex() Function
  4. Return for PHP dechex() Function
  5. Note for PHP dechex() Function
  6. Example - converts a decimal number into a binary number

Definition

The dechex() function converts a decimal number into a binary number.

Syntax

PHP dechex() Function has the following format.

string dechex ( int num )

Parameter

ParameterIs RequiredDescription
numberRequired. Decimal value to convert

Return

Item Description
Return Value A string that contains the hexadecimal number of the decimal value
Return Type String

Note

To convert hexadecimal to decimal, use the hexdec() function.

Example

Convert decimal to hexadecimal:


<?php//  j a va2s.com
print dechex(232); // "e8" 
print "\n";
echo dechex("30") . "\n";
echo dechex("10") . "\n";
echo dechex("1587") . "\n";
echo dechex("70");
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP decoct() Function
  2. Syntax for PHP decoct() Function
  3. Parameter for PHP decoct() Function
  4. Return for PHP decoct() Function
  5. Note for PHP decoct() Function
  6. Example - converts a decimal number into an octal number