Monday, May 18, 2026
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
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS