PHP: decbin() function
Description
The decbin() function is used to convert a decimal number to a binary number.
Version:
(PHP 4 and above)
Syntax:
decbin(num)
Parameter:
Name | Description | Required / Optional |
Type |
---|---|---|---|
num | The decimal value to convert | Required | Integer |
Return value:
Binary string representation of num.
Value Type: String.
Pictorial Presentation
Example:
<?php
$val1= 120;
$val2=7;
$val3=9899;
$zbin1=decbin($val1);
$zbin2=decbin($val2);
$zbin3=decbin($val3);
echo "Binary value of $val1 is $zbin1<br />";
echo "Binary value of $val2 is $zbin2<br />";
echo "Binary value of $val3 is $zbin3<br />";
?>
Output:
Binary value of 120 is 1111000 Binary value of 7 is 111 Binary value of 9899 is 10011010101011
View the example in the browser
See also
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/php/function-reference/decbin.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics