PHP | bindec( ) Function

While working with numbers, many times we need to convert the bases of number and one of the most frequent used conversion is binary to decimal conversion. PHP provides us with a built-in function bindec() for this purpose. The bindec() function in PHP is used to return the decimal equivalent of the binary number. It accepts a string argument which is the binary number we want to convert to decimal.
The parameter must be a string otherwise different data types will produce unexpected results.

Syntax:

bindec(binary_string)

Parameter: This function accepts a single parameter binary_string which represents the binary string you want to convert to decimal.



Return Value: It returns the decimal value of the binary number binary_string.

Examples:

Input : bindec('110011')
Output : 51

Input : bindec('000110011')
Output : 51

Input : bindec('111')
Output : 7

Below programs illustrate the bindec() function in PHP:

  • When ‘110011’ is passed as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php
      
    echo bindec('110011');
      
    ?>      

    chevron_right

    
    

    Output:

    51
  • When ‘000110011’ is passed as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php
      
    echo bindec('000110011');
      
    ?>      

    chevron_right

    
    

    Output:

    51
  • When ‘111’ is passed as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php
      
    echo bindec('111');
      
    ?>

    chevron_right

    
    

    Output:

    7

Reference:
http://php.net/manual/en/function.bindec.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.