<?Php
echo octdec(5); // Output 5
echo "<br>";
echo octdec(45); // Output 37
echo "<br>";
echo octdec(400); // Output is 256
echo "<br>";
echo octdec(657); // Output is 431
echo "<br>";
echo octdec(3000); // Output is 1536
?>
Syntax
number octdec(string $octal_number);
| Parameter | DESCRIPTION |
|---|---|
| $octal_number | Required : Octal number string as Input to convert to equivalent decimal base number. |
$octal = "12";
echo octdec($octal); // Output: 10 (Octal 12 is decimal 10)
$octal = "7654321";
echo octdec($octal); // Output: 2054353
$octal_values = ['10', '11', '12', '13'];
foreach ($octal_values as $oct) {
echo "Octal $oct = Decimal " . octdec($oct) . "
";
}
// Output:
// Octal 10 = Decimal 8
// Octal 11 = Decimal 9
// Octal 12 = Decimal 10
// Octal 13 = Decimal 11
$octal = "00077";
echo octdec($octal); // Output: 63 (Octal 77 is decimal 63)
$octal = "12abc34";
echo octdec($octal); // Output: 10 (Ignores the non-octal characters)
function convertOctal($octal) {
return octdec($octal);
}
echo convertOctal("145"); // Output: 101
These examples show how `octdec()` handles leading zeros, non-octal characters, and its use in a function.
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.