PHP | decoct( ) Function

In the earlier days of computing, octal numbers and the octal numbering system was very popular for counting inputs and outputs because as it works in counts of eight, inputs and outputs were in counts of eight, a byte at a time. Due to a wide usage of octal number system many times it happens that we require converting a decimal number to its decimal octal representation.There are many methods to convert a decimal number to its octal equivalent but they are a bit time-consuming.But PHP provides an inbuilt function which can be used to convert a decimal number to its octal equivalent.

The decoct() function in PHP is used to return the octal equivalent of a decimal number.
For 32-bit platforms, the largest number that can be converted is usually 4294967295 in decimal resulting in 37777777777 whereas in 64-bit platforms it is usually 9223372036854775807 in decimal resulting in 777777777777777777777.


string decoct(value)

Parameters: This function accepts a single parameter value. It is the decimal number whose octal equivalent you want to calculate.

Return Value: The decoct() function in PHP returns a string representing the octal equivalent of a decimal number passed to it as argument.


Input : decoct("35")
Output : 45

Input : decoct("67")
Output : 103

Input : decoct("4294967295")
Output : 37777777777

Below program illustrate the working of decoct() in PHP:





echo decoct("35") . "\n";
echo decoct("67") . "\n";
echo decoct("4294967295") . "\n";




Important points to note :

  • It converts a decimal number to its octal equivalent.
  • Negative numbers are supported by this function.
  • The octal number system is not as popular as hexadecimal number system these days.


My Personal Notes arrow_drop_up

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.