PHP Function Reference

PHP bindec() Function



The PHP bindec() function returns the decimal number equivalent to the binary number represented by the binary string argument.

The table below shows binary numbers converted into decimal numbers.

BinaryDecimalBinaryDecimal
00111115
111000016
1021111131
11310000032
100411111163
1015100000064
11061111111127
111710000000128
10008111110100500

Syntax

bindec(bin_string)

Parameters

bin_string Required. Specify the binary number to convert.

Note: The parameter must be a string. Using other data types will produce unexpected results.

Return Value

The decimal representation of a binary string argument.

Example:

In the example below, bindec() function returns the decimal representation of a binary string argument.

<?php
echo "bindec(0) = ".bindec(0)."\n";
echo "bindec(1) = ".bindec(1)."\n";
echo "bindec(10) = ".bindec(10)."\n";
echo "bindec(11) = ".bindec(11)."\n";
echo "bindec(100) = ".bindec(100)."\n";
echo "bindec(111) = ".bindec(111)."\n";
echo "bindec('11111') = ".bindec('11111')."\n";
echo "bindec('111011') = ".bindec('111011')."\n";
?>

The output of the above code will be:

bindec(0) = 0
bindec(1) = 1
bindec(10) = 2
bindec(11) = 3
bindec(100) = 4
bindec(111) = 7
bindec('11111') = 31
bindec('111011') = 59

❮ PHP Math Reference