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.