PHP hexdec() Function

In this chapter you will learn:

  1. Definition for PHP hexdec() Function
  2. Syntax for PHP hexdec() Function
  3. Parameter for PHP hexdec() Function
  4. Return for PHP hexdec() Function
  5. Example - Convert hexadecimal to decimal

Definition

The hexdec() function converts a hexadecimal number to a decimal number.

To convert decimal to hexadecimal, use dechex() function.

Syntax

PHP hexdec() Function has the following syntax.

hexdec(hex_string);

Parameter

ParameterIs RequiredDescription
hex_stringRequired. Specifies the hexadecimal string to convert

Return

ItemDesscription
Return Value The decimal value of hex_string
Return Type Float / Integer

Example

Convert hexadecimal to decimal:


<?php/*from ja v  a2  s  .  c o m*/
echo hexdec("1e") . "\n";
echo hexdec("a") . "\n";
echo hexdec("11ff") . "\n";
echo hexdec("cceeff");
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP hypot() Function
  2. Syntax for PHP hypot() Function
  3. Parameter for PHP hypot() Function
  4. Return for PHP hypot() Function
  5. Note for PHP hypot() Function
  6. Example - Calculate the hypotenuse of different right-angle triangles