Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
decbin() function in PHP
The decbin() function converts a decimal number to its binary representation and returns the result as a string.
Syntax
decbin(num)
Parameters
num − The decimal number to be converted to binary. Can be an integer or string representation of a number.
Return Value
Returns a string containing the binary representation of the given decimal number.
Example 1
Converting a decimal number to binary ?
<?php
echo decbin(3865);
?>
111100011001
Example 2
Converting another decimal number to binary ?
<?php
echo decbin(99);
?>
1100011
Example 3
Working with different decimal values ?
<?php
echo "Decimal 8 = Binary " . decbin(8) . "<br>";
echo "Decimal 15 = Binary " . decbin(15) . "<br>";
echo "Decimal 255 = Binary " . decbin(255) . "<br>";
?>
Decimal 8 = Binary 1000 Decimal 15 = Binary 1111 Decimal 255 = Binary 11111111
Conclusion
The decbin() function is useful for converting decimal numbers to binary format, commonly used in programming for bitwise operations and number system conversions.
Advertisements
