當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP bindec()用法及代碼示例


PHP bindec() 函數是數學函數,用於將二進製數轉換為十進製數。它返回 binary_string 的十進製值。

注意:通過調用 decbin() 函數將十進製數轉換為二進製數。

用法:

bindec(binary_string);
參數 描述 必需/可選
binary_string 指定要轉換的二進製字符串,參數值必須是字符串。 required

例子1

<?php
$binary='110011';
echo "Your binary number is:".$binary;
echo "<br>"."By using ?bindec()' function your decimal number is:".bindec($binary);
?>

輸出:

Your binary number is:110011
By using bindec()' function your decimal number is:51

例子2

<?php
$binary='01';
echo "Your binary number is:".$binary;
echo "<br>"."By using 'bindec()' function your decimal number is:".bindec($binary);
?>

輸出:

Your binary number is:01
By using 'bindec()' function your decimal number is:1

例子3

<?php
$binary='000110011';
echo "Your binary number is:".$binary;
echo "<br>"."By using 'bindec()' function your decimal number is:".bindec($binary);
?>

輸出:

Your binary number is:000110011
By using 'bindec()' function your decimal number is:51

示例 4

<?php
$binary='1010';
echo "Your binary number is:".$binary."<br>";
echo var_dump(bindec($binary));
?>

輸出:

Your binary number is:1010
int(10)

例 5

<?php
$binary='10000';
echo "Your binary number is:".$binary."<br>";	
echo "By using 'bindec()' function your decimal number is:".bindec($binary);
?>

輸出:

Your binary number is:10000
By using 'bindec()' function your decimal number is:16






相關用法


注:本文由純淨天空篩選整理自 PHP bindec() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。