bindec()
Published Jun 21, 2023
Contribute to Docs
The bindec()
function in PHP is used to convert a binary string representation to its decimal equivalent. It takes a binary string as input and returns the corresponding decimal value.
Syntax
bindec(string $binary_string): int
$binary_string
: The binary string to be converted to decimal.- Returns an integer representing the decimal value of the binary string.
Example
$binaryString = '101010';$decimalValue = bindec($binaryString);echo $decimalValue;
The output for the above code will be:
42
In the above example, the binary string 101010
is converted to its decimal equivalent, which is 42
.
Note: If the binary string contains characters other than
0
and1
, or if it’s an empty string, thebindec()
function will return0
. Additionally, if the binary string is too large to fit into an integer (defined by the system, usually 32 or 64 bits) the function may return an incorrect result due to integer overflow.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.