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.NoParameter & Description
1number
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

 Live Demo

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

 Live Demo

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

 Live Demo

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

 Live Demo

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

Updated on: 29-Jun-2020

52 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements