decbin

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

decbin十进制转换为二进制

说明

decbin(int $num): string

返回字符串,包含有给定 num 参数的二进制表示。

参数

num

要转换的十进制值

32 位机器上的输入范围
num num 返回值
0   0
1   1
2   10
... normal progression ...
2147483646   1111111111111111111111111111110
2147483647(最大有符号整数)   1111111111111111111111111111111 (31 1's)
2147483648 -2147483648 10000000000000000000000000000000
... normal progression ...
4294967294 -2 11111111111111111111111111111110
4294967295(最大无符号整数) -1 11111111111111111111111111111111 (32 1's)
64 位机器上的输入范围
num num 返回值
0   0
1   1
2   10
... normal progression ...
9223372036854775806   111111111111111111111111111111111111111111111111111111111111110
9223372036854775807(最大有符号整数)   111111111111111111111111111111111111111111111111111111111111111 (63 1's)
  -9223372036854775808 1000000000000000000000000000000000000000000000000000000000000000
... normal progression ...
  -2 1111111111111111111111111111111111111111111111111111111111111110
  -1 1111111111111111111111111111111111111111111111111111111111111111 (64 1's)

返回值

num 的二进制字符串表示

范例

示例 #1 decbin() 示例

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

以上例程会输出:

1100
11010

参见

  • bindec() - 二进制转换为十进制
  • decoct() - 十进制转换为八进制
  • dechex() - 十进制转换为十六进制
  • base_convert() - 在任意进制之间转换数字
  • printf() - 输出格式化字符串,格式使用 %b%032b%064b
  • sprintf(),格式使用 %b%032b%064b

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top