十進制轉換為二進制

decbin

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

decbin十進制轉換為二進制

說明

decbin(int $number): string

返回一字串,包含有給定 number 參數的二進制表示。所能轉換的最大數值為十進制的 4294967295,其結果為 32 個 1 的字串。

參數

number

Decimal value to convert

Range of inputs on 32-bit machines
positive numbernegative numberreturn value
0 0
1 1
2 10
... normal progression ...
2147483646 1111111111111111111111111111110
2147483647 (largest signed integer) 1111111111111111111111111111111 (31 1's)
2147483648-214748364810000000000000000000000000000000
... normal progression ...
4294967294-211111111111111111111111111111110
4294967295 (largest unsigned integer)-111111111111111111111111111111111 (32 1's)
Range of inputs on 64-bit machines
positive numbernegative numberreturn value
0 0
1 1
2 10
... normal progression ...
9223372036854775806 111111111111111111111111111111111111111111111111111111111111110
9223372036854775807 (largest signed integer) 111111111111111111111111111111111111111111111111111111111111111 (63 1's)
 -92233720368547758081000000000000000000000000000000000000000000000000000000000000000
... normal progression ...
 -21111111111111111111111111111111111111111111111111111111111111110
 -11111111111111111111111111111111111111111111111111111111111111111 (64 1's)

返回值

Binary string representation of number

範例

示例 #1 decbin() 例子

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

以上例程會輸出:

1100
11010

參見

  • bindec() - 二進制轉換為十進制
  • decoct() - 十進制轉換為八進制
  • dechex() - 十進制轉換為十六進制
  • base_convert() - 在任意進位制之間轉換數字
  • printf() - 輸出格式化字串, using %b, %032b or %064b as the format
  • sprintf(), using %b, %032b or %064b as the format

Leave a Reply

Your email address will not be published. Required fields are marked *