PHP bindec function – Convert a number between arbitrary bases

Description

The bindec() function converts a binary number into a decimal number. It takes just one parameter, which is the number to convert. For example:

print decbin("10000"); // 16

Syntax:

bindec(string $binary_string): int|float

Up to a 32-bit number, or 2,147,483,647 decimal, can be converted.

Parameters

Parameter Description
binary_string The binary string to convert. Any invalid characters in binary_string are silently ignored

Return Values

Decimal integer form of a binary number

Examples

Example 1: Convert a binary number to decimal:

$number = "101010"; 
echo "Binary $number is ", bindec($number), "in decimal"; 
Related Post