Home >>PHP Math Functions >PHP bindec() Function

PHP bindec() Function

PHP bindec() Function

PHP bindec() function is used to return the decimal equivalent of the given binary number. It accepts only a string argument having the binary number we want to convert to decimal value. The parameter passed to it must be a string. It returns the decimal value of the given input binary number.

Syntax:

  bindec($string);

Parameter Values

Parameter Description
string This is a required parameter. This parameter defines the input binary string to convert.

Here is an example of bindec() function in PHP:

<html>
<body>

<?php

echo bindec("0011") . "<br>";
echo bindec("01") . "<br>";

?>

</body>
</html>
Output:
3
1

Here is an another example of bindec() function in PHP:

<html>
<body>

<?php

echo bindec("01010110")."<br>";
echo bindec("0100010")."<br>";
echo bindec("100011")."<br>";
echo bindec("110011")."<br>";
echo bindec("001010101000")."<br>";
?>

</body>
</html>
Output:
86
34
35
51
680

No Sidebar ads