Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
communitycreator

What is the decoct method in PHP?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The decoct method converts a decimal number to an octal string.

Octal is the base-8 number system and uses digits 0 to 7.

Syntax

decoct(int $num): string

Parameters

The argument is the decimal number that will be converted to an octal string.

The maximum value that can be converted is based on the platform of the computer.

  • In 32-bit platforms, the largest decimal value that can be converted is 4294967295, resulting in 37777777777.

  • In 64-bit platforms, the largest decimal value that can be converted is 9223372036854775807, resulting in 777777777777777777777.

Return value

decoct returns the octal value of the argument as a string.

Code

<?php
$num = 8;
echo "octal value of ". $num. " is: ". decoct($num)."\n";
$num = 9;
echo "octal value of ". $num. " is: ". decoct($num)."\n";
$num = 10;
echo "octal value of ". $num. " is: ". decoct($num)."\n";
$num = 11;
echo "octal value of ". $num. " is: ". decoct($num)."\n";
$num = 12;
echo "octal value of ". $num. " is: ". decoct($num)."\n";
$num = 13;
echo "octal value of ". $num. " is: ". decoct($num)."\n";
$num = 100;
echo "octal value of ". $num. " is: ". decoct($num)."\n";
?>

Explanation

In the code above, we use the decoct method to convert the decimal numbers 8, 9, 10, 11, 12, 13, and 100 into octal representation.

RELATED TAGS

php
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring