bindec
Converts a binary string to a decimal number.
Syntax
bindec(string $binary_string): int|floatParameters
| Parameter | Type | Description |
|---|---|---|
| $binary_string | string | A string of zeros and ones. |
Return value
int|floatThe decimal number.
Examples
Binary to decimal:
<?php
echo bindec('1010'), ' ', bindec('11111111');Output:
10 255Notes
Stray characters in the string trigger a deprecation notice — validate the input first.
See also
- decbin — Converts a number to binary.
- base_convert — Converts a number from one base to another.
- hexdec — Converts a hexadecimal string to a decimal number.
In the tutorial
- Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.