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.
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:
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.
- How to get the function name inside a function in PHP ?
- PHP | Ds\Map xor() Function
- D3.js | d3.max() function
- PHP | pi( ) Function
- PHP | Ds\Set add() Function
- PHP | Ds\Map put() Function
- PHP | pow( ) Function
- PHP | each() Function
- PHP | Ds\Set xor() Function
- CSS | rgb() Function
- PHP | min( ) Function
- PHP | key() Function
- PHP | pos() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.