PHP decbin() Function
The PHP decbin() function returns a string which is the binary representation of a decimal number.
The table below shows decimal numbers converted into binary numbers.
Decimal | Binary | Decimal | Binary |
---|---|---|---|
0 | 0 | 15 | 1111 |
1 | 1 | 16 | 10000 |
2 | 10 | 31 | 11111 |
3 | 11 | 32 | 100000 |
4 | 100 | 63 | 111111 |
5 | 101 | 64 | 1000000 |
6 | 110 | 127 | 1111111 |
7 | 111 | 128 | 10000000 |
8 | 1000 | 500 | 111110100 |
Syntax
decbin(number)
Parameters
number |
Required. Specify the decimal number to convert. |
Return Value
Binary string representation of a decimal number.
Example:
In the example below, decbin() function returns the binary string representation of a given decimal number.
<?php echo "decbin(0) = ".decbin(0)."\n"; echo "decbin(1) = ".decbin(1)."\n"; echo "decbin(10) = ".decbin(10)."\n"; echo "decbin(50) = ".decbin(50)."\n"; echo "decbin(100) = ".decbin(100)."\n"; echo "decbin(500) = ".decbin(500)."\n"; echo "decbin('999') = ".decbin('999')."\n"; echo "decbin('1023') = ".decbin('1023')."\n"; ?>
The output of the above code will be:
decbin(0) = 0 decbin(1) = 1 decbin(10) = 1010 decbin(50) = 110010 decbin(100) = 1100100 decbin(500) = 111110100 decbin('999') = 1111100111 decbin('1023') = 1111111111
❮ PHP Math Reference