首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

decbin

(PHP 4, PHP 5, PHP 7)

decbin — Decimal to binary

Description

代码语言:javascript
复制
string decbin ( int $number )

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

Parameters

number

Decimal value to convert

positive number

negative number

return value

0

0

1

1

2

10

| ... normal progression ... |

| 2147483646 | ​ | 1111111111111111111111111111110 |

| 2147483647 (largest signed integer) | ​ | 1111111111111111111111111111111 (31 1's) |

| 2147483648 | -2147483648 | 10000000000000000000000000000000 |

| ... normal progression ... |

| 4294967294 | -2 | 11111111111111111111111111111110 |

| 4294967295 (largest unsigned integer) | -1 | 11111111111111111111111111111111 (32 1's) |

positive number

negative number

return value

0

0

1

1

2

10

| ... normal progression ... |

| 9223372036854775806 | ​ | 111111111111111111111111111111111111111111111111111111111111110 |

| 9223372036854775807 (largest signed integer) | ​ | 111111111111111111111111111111111111111111111111111111111111111 (63 1's) |

| ​ | -9223372036854775808 | 1000000000000000000000000000000000000000000000000000000000000000 |

| ... normal progression ... |

| ​ | -2 | 1111111111111111111111111111111111111111111111111111111111111110 |

| ​ | -1 | 1111111111111111111111111111111111111111111111111111111111111111 (64 1's) |

Return Values

Binary string representation of number

Examples

Example #1 decbin() example

代码语言:javascript
复制
<?php
echo decbin(12) . "\n";
echo decbin(26);
?>

The above example will output:

代码语言:javascript
复制
1100
11010

See Also

  • bindec() - Binary to decimal
  • decoct() - Decimal to octal
  • dechex() - Decimal to hexadecimal
  • base_convert() - Convert a number between arbitrary bases
  • printf() - Output a formatted string, using %b, %032b or %064b as the format
  • sprintf(), using %b, %032b or %064b as the format

← cosh

dechex →

代码语言:txt
复制
 © 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

扫码关注腾讯云开发者

领取腾讯云代金券