PHP Tutorial PHP Advanced PHP Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

PHP - Math bindec() Function



The PHP Math bindec() function returns the decimal number equivalent to the binary number represented by the binary string argument.

Syntax

bindec(bin_string)

Parameters

bin_string Required. Specify the binary number to convert.

Return Value

The decimal representation of a binary string argument.

Example:

In the example below, bindec() function returns the decimal representation of a binary string argument.

<?php
$x = '101010'; 
$y = 111000;
$z = 100000;

echo "bindec($x) returns: ".bindec($x)."\n";
echo "bindec($y) returns: ".bindec($y)."\n";
echo "bindec($z) returns: ".bindec($z)."\n";
?>

The output of the above code will be:

bindec(101010) returns: 42
bindec(111000) returns: 56
bindec(100000) returns: 32

❮ PHP Math Functions

5