The bindec() function converts a binary number to a decimal number.
number bindec ( string $binary_string )
Returns the decimal equivalent of the binary number represented by the binary_string argument.
bindec() converts a binary number to an integer or, if needed for size reasons, float.
bindec() interprets all binary_string values as unsigned integers. This is because bindec() sees the most significant bit as another order of magnitude rather than as the sign bit.
Output of the above example on 32 bit machines:
input: 1073741823 binary: 00111111111111111111111111111111 bindec(): 1073741823 input: 1073741824 binary: 01000000000000000000000000000000 bindec(): 1073741824 NOTE: See the rollover? Watch it next time around... input: 2147483647 binary: 01111111111111111111111111111111 bindec(): 2147483647 NOTE: PHP_INT_MAX input: -2147483648 binary: 10000000000000000000000000000000 bindec(): 2147483648 NOTE: interpreted to be one more than PHP_INT_MAX input: -1 binary: 11111111111111111111111111111111 bindec(): 4294967295 NOTE: interpreted to be the largest unsigned integer
Parameter | Description |
---|---|
binary_string | The binary string to convert |
The decimal value of binary_string