octdec(): decimal equivalent of octal number

<?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);
ParameterDESCRIPTION
$octal_numberRequired : Octal number string as Input to convert to equivalent decimal base number.
The output is number converted to decimal base system.

Example: Simple Octal to Decimal Conversion

$octal = "12";
echo octdec($octal);  // Output: 10 (Octal 12 is decimal 10)

Example: Large Octal Conversion

$octal = "7654321";
echo octdec($octal);  // Output: 2054353

Example: Converting a List of Octal Values

$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

Example: Octal with Leading Zeros

$octal = "00077";
echo octdec($octal);  // Output: 63 (Octal 77 is decimal 63)

Example: Mixed Octal and Non-Octal Strings

$octal = "12abc34";
echo octdec($octal);  // Output: 10 (Ignores the non-octal characters)

Example: Octal to Decimal in a Function

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.
Math Functions base_convert(): Convert number From any base to other decbin() Binary equivalent of decimal number dechex(): Convert decimal number to hexadecimal system
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer