decoct():octal equivalent of decimal number

``````<?Php
echo decoct(5); // Output 5
echo "<br>";
echo decoct(55); // Output 67
echo "<br>";
echo decoct(500); // Output is 764
echo "<br>";
echo decoct(658); // Output is 1222
echo "<br>";
echo decoct(3000); // Output is 5670
?>``````
Syntax
``string decoct(int \$number);``
ParameterDESCRIPTION
\$numberRequired : Decimal number as Input to convert to equivalent octal base number.
The output is string converted to octal base system.

``````\$hex_value = 'A1';
\$decimal_value = hexdec(\$hex_value);
echo decoct(\$decimal_value);  // Output: 241``````

Example: Handling Large Numbers

``````\$large_number = 123456789;
echo decoct(\$large_number);  // Output: 726746425``````

Example: Convert Binary to Octal

``````\$binary_value = '1101';
\$decimal_value = bindec(\$binary_value);
echo decoct(\$decimal_value);  // Output: 15``````

Example: Octal Conversion for Negative Numbers

``````\$negative_value = -100;
echo decoct(\$negative_value);  // Output: 37777777634 (negative numbers in octal)``````

Example: Working with Octal and Strings

``````\$number = '123';
\$decimal_value = (int)\$number;
echo decoct(\$decimal_value);  // Output: 173 (string treated as integer)``````

Subscribe to our YouTube Channel here

Subscribe

* indicates required
Subscribe to plus2net

plus2net.com