PHP | bindec( ) Function
While working with numbers, many times we need to convert the bases of number and one of the most frequent used conversion is binary to decimal conversion. PHP provides us with a built-in function bindec() for this purpose. The bindec() function in PHP is used to return the decimal equivalent of the binary number. It accepts a string argument which is the binary number we want to convert to decimal.
The parameter must be a string otherwise different data types will produce unexpected results.
Syntax:
bindec(binary_string)
Parameter: This function accepts a single parameter binary_string which represents the binary string you want to convert to decimal.
Return Value: It returns the decimal value of the binary number binary_string.
Examples:
Input : bindec('110011')
Output : 51
Input : bindec('000110011')
Output : 51
Input : bindec('111')
Output : 7
Below programs illustrate the bindec() function in PHP:
- When ‘110011’ is passed as a parameter:
<?phpecho bindec('110011');?>chevron_rightfilter_noneOutput:
51
- When ‘000110011’ is passed as a parameter:
<?phpecho bindec('000110011');?>chevron_rightfilter_noneOutput:
51
- When ‘111’ is passed as a parameter:
<?phpecho bindec('111');?>chevron_rightfilter_noneOutput:
7
Reference:
http://php.net/manual/en/function.bindec.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- PHP | ord() Function
- p5.js | nf() Function
- p5.js | nfc() function
- p5.js | arc() Function
- p5.js | box() Function
- PHP | dir() Function
- CSS | hsl() Function
- p5.js | day() function
- CSS | rgb() Function
- D3.js | d3.map.has() Function
- D3.js | d3.map.get() Function
- PHP | exp() Function
- D3.js | d3.min() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



