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.

Updated on: 2026-03-15T07:26:33+05:30

160 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements