How to use the octdec() function In PHP

In this approach, we are using PHP’s built-in octdec() function to convert octal numbers to decimal. This function takes an octal input as a string and returns its decimal equivalent. The example demonstrates how to use octdec() with different octal inputs, showcasing the conversion process.

Syntax:

octdec(value)

Example: The below example uses octdec() function to perform Octal to Decimal conversion in PHP.

PHP
<?php
$input = "67";
$decimal = octdec($input);
echo "Octal $input is Decimal $decimal\n";
$input = "512";
$decimal = octdec($input);
echo "Octal $input is Decimal $decimal\n";
$input = "123";
$decimal = octdec($input);
echo "Octal $input is Decimal $decimal\n";
?>

Output:

Octal 67 is Decimal 55
Octal 512 is Decimal 330
Octal 123 is Decimal 83

Octal to Decimal Converter in PHP

Given an octal number as input, we need to write a program in PHP to convert the given octal number into an equivalent decimal number.

Below are the approaches to performing octal to decimal conversion in PHP.

Table of Content

  • Using the octdec() function
  • Using Manual Conversion

Similar Reads

Using the octdec() function

In this approach, we are using PHP’s built-in octdec() function to convert octal numbers to decimal. This function takes an octal input as a string and returns its decimal equivalent. The example demonstrates how to use octdec() with different octal inputs, showcasing the conversion process....

Using Manual Conversion

In this approach, we are manually converting octal numbers to decimal by iterating through each digit in the octal number, multiplying it by the corresponding power of 8, and accumulating the results to obtain the decimal value....