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.
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.
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
For example, consider the following cases to observe the functioning of the function in PHP.
<?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.
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.