# Convert decimal to octal and octal to decimal in PHP

by anonymous

• 0
• 0
• 0
95 views
```
Orignal Source:http://codingvilla.com/convert-decimal-octal-php-single-article-572.aspx
Decimal Values:

Decimal data type is a primitive data type that represents the non-repeating decimal fraction without round-off to apply arithmetic operation on them. Decimal values are represented as fixed point value.

For example:

\$Value=0.3; \$Value2=255

Octal values:

Octal number is a base 8 number system, represented from 0-7 digits. Octal number is basically a decimal number that is written in base 8.

For example:

12748(octal number)
1128(octal number)

Convert decimal into octal using decoct () function in php:

To convert decimal number into octal we use decoct () function in php.  It is a built in function in php that takes decimal value as a parameter and returns an octal converted value.

Code:

<?php
\$orig_dec = 34672;
\$dec2oct = decoct(\$orig_dec);
echo "original decimal number: \$orig_dec <br>";
echo "new octal number: \$dec2oct <br>";
?>

This simple code is used to convert decimal number into octal number using decoct() function in php.

Convert octal into decimal using octdec () function in php:

To convert octal number into decimal we use octdec () function in php.  It is a built in function in php that takes octal value as a parameter and returns an decimal converted value.

Code:

<?php
\$orig_oct=103560;
\$oct2dec = octdec(\$orig_oct);
echo "original octal number: \$orig_oct<br>";
echo "new decimal number: \$dec2oct <br>";
?>

This simple code is used to convert octal number into decimal number using octdec() function in php.

This simple article tells that how we can convert decimal number into octal and octal into decimal using decoct() & octdec() function in php.
```