Friday, October 10, 2025
HomeLanguagesPHP bindec( ) Function

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:




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

    
    

    Output:

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




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

    
    

    Output:

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




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

    
    

    Output:

    7

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

RELATED ARTICLES

Most Popular

Dominic
32349 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6717 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7097 POSTS0 COMMENTS
Thapelo Manthata
6792 POSTS0 COMMENTS
Umr Jansen
6792 POSTS0 COMMENTS