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 a Lead Software Engineer at Naukri.com. He passed out of Delhi College of Engineering in 2016 and likes to play Foosball. He loves traveling and is an exercise freak. His expertise includes Java, PHP, Python, Databases, Design and Architecture.