PHP | octdec( ) Function

In the earlier days of computing, octal numbers and the octal numbering system was very popular for counting inputs and outputs because as it works in counts of eight, inputs and outputs were in counts of eight, a byte at a time. Due to a wide usage of octal number system many times it happens that we require converting an octal number to its decimal equivalent. There are many methods to convert an octal number to its decimal equivalent but they are a bit time-consuming. But PHP provides us with an in-built function which can be used to convert an octal number to its decimal equivalent.

The octdec() function is a built in function in PHP and is used to calculate the decimal equivalent of an octal number. The octdec() function converts numbers that are too large to fit into the integer type, larger values are returned as a float in that case.

Syntax:



octdec(value)

Parameters: This function accepts a single parameter $value . It is a string which represents the octal number whose decimal equivalent you want to find.

Return Value:It returns the decimal representation of octal number passed as a string to the function.

Examples:

Input : octdec("46")
Output : 38

Input : octdec("3098")
Output : 24

Input : octdec("-105")
Output : 69

Below program illustrate the working of octdec() in PHP:

  1. When a positive number is passed as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php
      
    echo octdec("3098");
      
    ?>

    chevron_right

    
    

    Output:

    24
  2. When a negative number is passed as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php
      
    echo octdec("-105");
      
    ?>

    chevron_right

    
    

    Output:

    69

Important points to note:

  • It converts an octal number to its decimal equivalent.
  • It returns the values as float if the numbers are too large to be returned as integer type .
  • Octal number system is not as popular as hexadecimal number system these days.

Reference:
http://php.net/manual/en/function.octdec.php



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.