decoct() returns the octal representation of an integer as a string.
$number = 64;
echo decoct($number); // 100
<?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);
| Parameter | DESCRIPTION |
|---|---|
| $number | Required : Decimal number as Input to convert to equivalent octal base number. |
$hex_value = 'A1';
$decimal_value = hexdec($hex_value);
echo decoct($decimal_value); // Output: 241
$large_number = 123456789;
echo decoct($large_number); // Output: 726746425
$binary_value = '1101';
$decimal_value = bindec($binary_value);
echo decoct($decimal_value); // Output: 15
For negative integers, decoct() reflects the platform's two's-complement integer width. Avoid documenting one fixed octal result for every server.
$negative_value = -100;
$octal = decoct($negative_value);
echo $octal; // Platform-dependent representation
$number = '123';
$decimal_value = (int)$number;
echo decoct($decimal_value); // Output: 173 (string treated as integer)
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.