什么是在PHP二进制preFIX? [英] What's the prefix for binary in PHP?

查看:218
本文介绍了什么是在PHP二进制preFIX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是既不 0X 也不 0 ;它是什么?有没有?

It's neither 0x nor 0; what is it? Is there?

推荐答案

自PHP 5.4+的preFIX为二进制数是:

As of PHP 5.4+ the prefix for binary number is:

0b



为更早期版本中,不存在这样的preFIX。相反,你可以使用 0X ,为十六进制。

有关更多的信息,请参阅 整数PHP的部分手动

For more informations, see the Integers section of the PHP manual.

不过,如果你真的需要PHP 5.4之前写使用二进制值,可以使用 bindec 功能,这需要包含二进制字符串,并返回相应的值。

Still, if you really need to write values using binary before PHP 5.4, you can use the bindec function, that takes a string containing the binary, and returns the corresponding value.

例如,code以下部分:

For example, the following portion of code :

echo bindec('10011');

会得到你:

19

但要注意,你不应该这样做过于频繁:调用一个函数,在每次执行脚本的时间演出相当不错^^
结果相反,它真的是一个更好的解决方案使用十六进制,写你的值,其中每个数位codeS 4位。

But note you shouldn't do that too often : calling a function to do that each time the script is executed is quite bad for performances ^^
Instead, it's really a better solution to write your values using hexadecimal, where each digit codes for 4 bits.

这篇关于什么是在PHP二进制preFIX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆