当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。