PHP decbin Function | Convert Decimal To Binary String

PHP decbin is an inbuilt Math Function in PHP. It converts an input decimal integer into its corresponding binary representation string.

You can convert a binary string to its corresponding decimal integer using PHP bindec Function.


decbin ($integer)


The function accepts only one parameter. The decimal value for which you want to find the binary representation is the input to the function.

Return Value

The function returns the corresponding binary string for the decimal value.

Input: decbin(4)
Output: 100

Input: decbin(2147483647)
Output: 1111111111111111111111111111111 (31 1s)

Input: decbin(-1)
Output: 11111111111111111111111111111111 (32 1s)
PHP decbin Function


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


	echo decbin(4); //100

	echo decbin(2147483647); //1111111111111111111111111111111

	echo decbin(-1); //11111111111111111111111111111111



In conclusion, we discussed the PHP decbin Function. You can read more about it on the Official PHP Documentation. Additionally, you can also read more about PHP Math Functions on Concatly.

Spread the Knowledge

2 thoughts on “PHP decbin Function | Convert Decimal To Binary String

Leave a Reply

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