php8.5
Home/ Manual/ math / functions/ decbin

decbin

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Decimal to binary

Description

decbin(int $num): string

Returns a string containing a binary representation of the given num argument.

Parameters

num

Decimal value to convert

positive numnegative numreturn value
00
11
210
... normal progression ...
21474836461111111111111111111111111111110
2147483647 (largest signed integer)1111111111111111111111111111111 (31 1's)
2147483648-214748364810000000000000000000000000000000
... normal progression ...
4294967294-211111111111111111111111111111110
4294967295 (largest unsigned integer)-111111111111111111111111111111111 (32 1's)
positive numnegative numreturn value
00
11
210
... normal progression ...
9223372036854775806111111111111111111111111111111111111111111111111111111111111110
9223372036854775807 (largest signed integer)111111111111111111111111111111111111111111111111111111111111111 (63 1's)
-92233720368547758081000000000000000000000000000000000000000000000000000000000000000
... normal progression ...
-21111111111111111111111111111111111111111111111111111111111111110
-11111111111111111111111111111111111111111111111111111111111111111 (64 1's)

Return Values

Binary string representation of num

Examples

decbin() example

php
<?php
echo decbin(12) . "\n";
echo decbin(26);
?>

The above example will output:

output
1100
11010

See Also

Source: reference/math/functions/decbin.xml · from the official PHP manual (php/doc-en)