 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP bindec() Function
Definition and Usage
The bindec() function returns decinmal equivalent of a binary number represented as a string argument. Binary number inside string is interpreted as unigned integer.
This function returns a decimal integer. However, it may return float for size reasons.
Syntax
bindec ( string $binary_string ) : number
Parameters
| Sr.No | Parameter & Description | 
|---|---|
| 1 | binary_string A string containing binary number representation. Invalid characters (other than 1 and 0) are ignored. | 
Return Values
PHP bindec() function returns decimal equivalent of given binary number inside string.
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
Following example calculates decimal equivalent of '1101' and returns 13 −
<?php    $arg='1101';    $val=bindec($arg);    echo "bindec('" . $arg . "') = " . $val; ?> Output
This will produce following result −
bindec('1101') = 13 Example
Following example shows that characters other than 1 or 0 are ignored. Hence '110011.11' is treated as '11001111' which 207 in decimal system. −
<?php    $arg='110011.11';    $val=bindec($arg);    echo "bindec('" . $arg . "') = " . $val; ?> Output
This will produce following result −
bindec('110011.11') = 207 Example
If string contains all non-binary characters, result is 0 −
<?php    $arg='Hello';    $val=bindec($arg);    echo "bindec('" . $arg . "') = " . $val; ?> Output
This will produce following result −
bindec('Hello') = 0 Example
Following example shows that bindec() function treats the binary string to contain unsigned integer
<?php    $arg='-1111';    $val=bindec($arg);    echo "bindec('" . $arg . "') = " . $val; ?> Output
This will produce following result −
bindec('-1111') = 15