Home > Backend Development > PHP Tutorial > php怎么实现二进制转十进制?

php怎么实现二进制转十进制?

PHPz
Release: 2020-06-24 16:53:46
Original
1863 people have browsed it

php怎么实现二进制转十进制?

php怎么实现二进制转十进制?

在PHP中,可以使用bindec()函数来实现二进制转十进制。bindec()函数可以把二进制转换为十进制。

语法

bindec(binary_string)
Copy after login

参数:

binary_string:必需。规定要转换的二进制数。

echo bindec('110011'); //输出 51 
echo bindec('000110011'); //输出 51 
echo bindec('111'); //输出 7
Copy after login

说明

返回 binary_string 参数所表示的二进制数的十进制等价值。

bindec() 函数将一个二进制数转换成 integer。可转换的最大的数为 31 位 1 或者说十进制的 2147483647。PHP 4.1.0 开始,该函数可以处理大数值,这种情况下,它会返回 float 类型。

示例:

<?php
echo bindec("0011");
echo bindec("01");
echo bindec("11000110011");
echo bindec("111");
?>
Copy after login

输出:

3
1
1587
7
Copy after login

更多相关知识,请访问 PHP中文网!!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template