成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁(yè) ? 技術(shù)教程 ? PHP:bindec()的用法_Math函數(shù)
全站頭部文字 我要出現(xiàn)在這里
PHP:bindec()的用法_Math函數(shù) 733 2024-01-01   

bindec

(PHP 4, PHP 5)

bindec — 二進(jìn)制轉(zhuǎn)換為十進(jìn)制

說明

number bindec ( string $binary_string )

返回 binary_string 參數(shù)所表示的二進(jìn)制數(shù)的十進(jìn)制等價(jià)值。

bindec() 將一個(gè)二進(jìn)制數(shù)轉(zhuǎn)換成 integer,或者出于大小的需要,轉(zhuǎn)換為 float 類型。

bindec() 將所有的 binary_string 值解釋為無符號(hào)整數(shù)。這是由于 bindec() 函數(shù)將其最高有效位視為數(shù)量級(jí)而非符號(hào)位。

參數(shù)

binary_string

要轉(zhuǎn)換的二進(jìn)制字符串

Warning

參數(shù)必須為字符串。使用其他數(shù)據(jù)類型會(huì)導(dǎo)致不可預(yù)知的結(jié)果。

返回值

binary_string 的十進(jìn)制數(shù)值

更新日志

版本 說明 4.1.0 本函數(shù)如今可以轉(zhuǎn)換超過程序運(yùn)行平臺(tái)中 integer 類型最大值的數(shù),此時(shí)其值會(huì)返回為 float 類型。

范例

Example #1 bindec() 例子

<?php
echo bindec('110011') . "n";
echo bindec('000110011') . "n";

echo bindec('111');
?>

以上例程會(huì)輸出:

51
51
7

Example #2 bindec() 將輸入解讀為無符號(hào)整數(shù)

<?php
/*
 * The lesson from this example is in the output
 * rather than the PHP code itself.
 */

$magnitude_lower = pow(2, (PHP_INT_SIZE * 8) - 2);
p($magnitude_lower - 1);
p($magnitude_lower, 'See the rollover?  Watch it next time around...');

p(PHP_INT_MAX, 'PHP_INT_MAX');
p(~PHP_INT_MAX, 'interpreted to be one more than PHP_INT_MAX');

if (PHP_INT_SIZE == 4) {
    $note = 'interpreted to be the largest unsigned integer';
} else {
    $note = 'interpreted to be the largest unsigned integer
              (18446744073709551615) but skewed by float precision';
}
p(-1, $note);


function p($input, $note = '') {
    echo "input:        $inputn";

    $format = '%0' . (PHP_INT_SIZE * 8) . 'b';
    $bin = sprintf($format, $input);
    echo "binary:       $binn";

    ini_set('precision', 20);  // For readability on 64 bit boxes.
    $dec = bindec($bin);
    echo 'bindec():     ' . $dec . "n";

    if ($note) {
        echo "NOTE:         $noten";
    }

    echo "n";
}
?>

以上例程在 32 位機(jī)器上的輸出:

input:        1073741823
binary:       00111111111111111111111111111111
bindec():     1073741823
input:        1073741824
binary:       01000000000000000000000000000000
bindec():     1073741824
NOTE:         See the rollover?  Watch it next time around...
input:        2147483647
binary:       01111111111111111111111111111111
bindec():     2147483647
NOTE:         PHP_INT_MAX
input:        -2147483648
binary:       10000000000000000000000000000000
bindec():     2147483648
NOTE:         interpreted to be one more than PHP_INT_MAX
input:        -1
binary:       11111111111111111111111111111111
bindec():     4294967295
NOTE:         interpreted to be the largest unsigned integer

以上例程在 64 位機(jī)器上的輸出:

input:        4611686018427387903
binary:       0011111111111111111111111111111111111111111111111111111111111111
bindec():     4611686018427387903
input:        4611686018427387904
binary:       0100000000000000000000000000000000000000000000000000000000000000
bindec():     4611686018427387904
NOTE:         See the rollover?  Watch it next time around...
input:        9223372036854775807
binary:       0111111111111111111111111111111111111111111111111111111111111111
bindec():     9223372036854775807
NOTE:         PHP_INT_MAX
input:        -9223372036854775808
binary:       1000000000000000000000000000000000000000000000000000000000000000
bindec():     9223372036854775808
NOTE:         interpreted to be one more than PHP_INT_MAX
input:        -1
binary:       1111111111111111111111111111111111111111111111111111111111111111
bindec():     18446744073709551616
NOTE:         interpreted to be the largest unsigned integer
              (18446744073709551615) but skewed by float precision

參見

decbin() - 十進(jìn)制轉(zhuǎn)換為二進(jìn)制 octdec() - 八進(jìn)制轉(zhuǎn)換為十進(jìn)制 hexdec() - 十六進(jìn)制轉(zhuǎn)換為十進(jìn)制 base_convert() - 在任意進(jìn)制之間轉(zhuǎn)換數(shù)字



主站蜘蛛池模板: 电影《死亡权限》免费观看| 颂赞诗歌| 湖南卫视节目表今天| 杨子纯| 吴京电影大全| 孤掷一注在线观看| 吸痰护理ppt课件| 夕阳老人视频| 影子人| 城市风云儿| 动物园作文| 感冒难受的图片| 迪迦奥特曼头像| 西野翔电影| 彼岸花电影| 洛可电影《妮娜》在线观看| 50字精美优秀教师个人简介| 应昊茗| 挠vk| 陈建斌电影| 我和我的父辈电影免费播放完整版| 刀客家族的女人演员表| 松树的风格原文完整版| 四个房间电影| 敦煌夜谭在线观看| 《画江湖之不良人》| 街头霸王 1994 尚格·云顿| 想你的时候问月亮男声沙哑版| 生死相随| 鹰与枭全部演员表| 白宝山电视剧26集免费观看| 金发女郎| 龙的传人第四季| 我爱你在线观看| 自拍性视频| 孕妇不能吃什么| 扭曲的欲望| 二年级上册数学试卷题全套| 丰崎爱生| 刀客家族的女人演员表| 尤勇智的个人资料简介|

!!!站長(zhǎng)長(zhǎng)期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長(zhǎng)微信:lxwl520520

站長(zhǎng)QQ:1737366103