It's neither 0x
nor 0
; what is it? Is there?
PHP provides us with a built-in function, decbin() for this purpose. The decbin() function in PHP is used to return a string containing a binary representation of the given decimal number argument. decbin stands for decimal to binary. Syntax: string decbin(value)
'0b' is used to tell the computer that the number you typed is a base-2 number not a base-10 number. Submitted by Omar Zaffar Khan.
Worldwide, there are many individuals and several subcultures that can be considered exceptions to the gender binary or specific transgender identities. In addition to individuals whose bodies are naturally intersex, there are also specific ceremonial and social roles that are seen as third gender.
As of PHP 5.4+ the prefix for binary number is:
0b
0x
, for hexadecimal. For more informations, see the Integers section of the PHP manual.
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.
For example, the following portion of code :
echo bindec('10011');
Will get you :
19
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.
New in PHP 5.4 is the binary prefix, 0b
. Think about portability when using it though; you'll need to be able to guarantee the server runs PHP 5.4+.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With