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.
The function accepts only one parameter. The decimal value for which you want to find the binary representation is the input to the function.
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)
For example, consider the following cases to observe the functioning of the function in PHP.
<?php echo decbin(4); //100 echo decbin(2147483647); //1111111111111111111111111111111 echo decbin(-1); //11111111111111111111111111111111 ?>
Vishesh is currently working as an Intermediate Software Engineer with Orion Health, New Zealand. He graduated with a Masters in Information Technology from the University of Auckland in 2021. With more than 4 years of work experience, his expertise includes Java, Python, Machine Learning, PHP, Databases, Design and Architecture.