Menu Home

bindec

osbo.com | PHP | Functions | bindec

Binary to decimal

Syntax

bindec ( string $binary_string ) : number

Parameters

binary_string

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

Binary Decimal
0 0
1 1
10 2
... ...
111111111111111111111111111111111111111111111111111111111111110 9223372036854775806
111111111111111111111111111111111111111111111111111111111111111 (63) 9223372036854775807 (largest signed integer)
1000000000000000000000000000000000000000000000000000000000000000 9223372036854775808
... ...
1111111111111111111111111111111111111111111111111111111111111110 18446744073709551614
1111111111111111111111111111111111111111111111111111111111111111 (64) 18446744073709551615 (largest unsigned integer)

Return

The decimal value of binary_string

Examples

1

<?

$binary_string1 = "0";
$binary_string2 = "023456789abcdefghijklmnopqrstuvwxyz";

$return1 = bindec($binary_string1);
$return2 = bindec($binary_string2);

echo $return1 . PHP_EOL;
echo $return2;

?>
0
0

2

<?

$binary_string = "1";

$return = bindec($binary_string);

echo $return;

?>
1

3

<?

$binary_string = "10";

$return = bindec($binary_string);

echo $return;

?>
2

4

<?

$binary_string = "111111111111111111111111111111111111111111111111111111111111110";

$return = bindec($binary_string);

echo $return;

?>
9223372036854775806

5

<?

$binary_string = "111111111111111111111111111111111111111111111111111111111111111";

$return = bindec($binary_string);

echo $return;

?>
9223372036854775807

6

<?

ini_set("precision", 19);

$binary_string = "1000000000000000000000000000000000000000000000000000000000000000";

$return = bindec($binary_string);

echo $return;

?>
9223372036854775808

7

<?

ini_set("precision", 20);

$binary_string = "1111111111111111111111111111111111111111111111111111111111111110";

$return = bindec($binary_string);

echo $return;

?>
18446744073709551616

8

<?

ini_set("precision", 20);

$binary_string = "1111111111111111111111111111111111111111111111111111111111111111";

$return = bindec($binary_string);

echo $return;

?>
18446744073709551616

PHP