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.

Syntax:



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.

Examples:

Input : decoct("35")
Output : 45

Input : decoct("67")
Output : 103

Input : decoct("4294967295")
Output : 37777777777

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
echo decoct("35") . "\n";
echo decoct("67") . "\n";
echo decoct("4294967295") . "\n";
  
?>

chevron_right


Output:

43
103
37777777777

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.

Reference:
http://php.net/manual/en/function.decoct.php



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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 contribute@geeksforgeeks.org to report any issue with the above content.