bindec()
bindec() — Binary to decimal.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Returns the decimal equivalent of the binary number represented by the binary_string argument.
Signature
bindec(string $binary_string): int|float
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $binary_string | string | The binary string to convert. Any invalid characters in binary_string are silently ignored. As of PHP 7.4.0 supplying any invalid characters is deprecated. |
Return value
The decimal value of binary_string
Example
A runnable snippet:
echo bindec('110011') . "\n"; echo bindec('000110011') . "\n"; echo bindec('111');
Output:
51 51 7
Changelog
| Version | Change |
|---|---|
| 7.4.0 | Passing invalid characters will now generate a deprecation notice. The result will still be computed as if the invalid characters did not exist. |
See also
decbin(), octdec(), hexdec(), base_convert()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page bindec() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.