- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 decoct() Function
Definition and Usage
The decoct() function returns a string that contains octal equivalent of given decimal number argument.
This function returns a string with octal characters (0 to 7).
Syntax
decoct ( int $number ) : string
Parameters
Sr.No | Parameter & Description |
---|---|
1 | number A decimal number to be converted in equivalent octal representation |
Return Values
PHP decoct() function returns an octal 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 '1751' −
<?php $arg=1001; $val=decoct($arg); echo "decoct(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
decoct(1001) = 1751
Example
Following example shows that fractional part of given number is ignored. Hence 100.55 is treated as 100 which is '144' in octal system. −
<?php $arg=100.55; $val=decoct($arg); echo "decoct(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
decoct(100.55) = 144
Example
If string is provided as argument, result is 0 −
<?php $arg="Hello"; $val=decoct($arg); echo "decoct(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
decoct(Hello) = 0
Example
Largest integer on 64 bit system is 9223372036854775807. The decoct() function returns following result
<?php $arg=9223372036854775807; $val=decoct($arg); echo "decoct(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
decoct(9223372036854775807) = 777777777777777777777