
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP dechex() Function
Definition and Usage
The dechex() function returns a string that contains hexadecimal equivalent of given decimal number argument.
This function returns a string with hexadecimal characters.
Syntax
dechex ( int $number ) : string
Parameters
Sr.No | Parameter & Description |
---|---|
1 |
number A decimal number to be converted in equivalent hexadecimal representation |
Return Values
PHP dechex() function returns a hexadecimal number inside string.
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
Following example calculates binary equivalent of 1001 and returns '3e9' −
<?php $arg=1001; $val=dechex($arg); echo "dechex(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
dechex(1001) = 3e9
Example
Following example shows that fractional part of given number is ignored. Hence 100.55 is treated as 100 which is '64' in hexadecimal system. −
<?php $arg=100.55; $val=dechex($arg); echo "dechex(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
dechex(100.55) = 64
Example
If string is provided as argument, result is 0 −
<?php $arg="Hello"; $val=dechex($arg); echo "dechex(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
dechex(Hello) = 0
Example
For negative decimal number, conversion is done using hexadecimal 2's complement method. Following example returns hexadecimal equivalent of -10
<?php $arg='-10'; $val=dechex($arg); echo "dechex(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
dechex(-10) = fffffffffffffff6