PHP | decbin( ) Function
While working with numbers, many times we need to convert the bases of number and one of the most frequent used conversion is decimal to binary conversion. PHP provides us with a built-in function, decbin() for this purpose.The decbin() function in PHP is used to return a string containing a binary representation of the given decimal number argument.
decbin stands for decimal to binary.
Syntax:
string decbin(value)
Parameters: This function accepts a single parameter value. It is the decimal number which you want to convert in binary representation.
Return Value: It returns a string that represent the binary value of the decimal number passed to the function as argument.
Examples:
Input : decbin(12) Output : 1100 Input : decbin(26) Output : 11010 Input : decbin(2147483647) Output : 1111111111111111111111111111111 (31 1's)
Below programs illustrate the decbin() function in PHP:
- Passing 12 as a parameter
<?
php
echo decbin(12);
?>
Output:
1100
- Passing 26 as a parameter:
<?
php
echo decbin(26);
?>
Output:
11010
- When the largest signed integer is passed as a parameter:
<?
php
echo decbin(2147483647);
?>
Output:
1111111111111111111111111111111
Reference:
http://php.net/manual/en/function.decbin.php