PHP Function Reference

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.

DecimalBinaryDecimalBinary
00151111
111610000
2103111111
31132100000
410063111111
5101641000000
61101271111111
711112810000000
81000500111110100

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