PHP bindec Function | Convert a Binary to Decimal

PHP bindec is an inbuilt Math Function in PHP. It converts an input binary string into its corresponding decimal representation. In this article, we will discuss the PHP bindec Function.

You can use the PHP decbin Function to convert a decimal integer to it’s corresponding binary string.


bindec ($binaryString)


The function accepts only one parameter. The binary string for which you want to find the decimal representation is the input to the function. Also, the input must be a string, otherwise the function may produce unexpected results.

Note: The function always interprets the binary string as an unsigned integer. This is because it sees the most significant bit as an order of magnitude and not the sign.

Return Value

The bindec Function in PHP returns the corresponding decimal value for the input binary string.

Input: bindec('100')
Output: 4

Input: bindec('001101')
Output: 13

Input: bindec('1101')
Output: 13
PHP bindec Function


For example, consider the following cases to observe the functioning of the function in PHP.


	echo bindec('100'); //4

	echo bindec('001101'); //13

	echo bindec('1101'); //13



In conclusion, we discussed the PHP bindec Function. It converts an input binary string to its corresponding decimal value. Also, you can read more about it on the Official PHP Documentation. Additionally, you can also read about PHP Math Functions on Concatly.

Spread the Knowledge

One thought on “PHP bindec Function | Convert a Binary to Decimal

Leave a Reply

Your email address will not be published. Required fields are marked *