0; what is it? Is there?
As of PHP 5.4+ the prefix for binary number is:
For ealier version, there is no such prefix. Instead, you can use
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 :
Will get you :
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+.
From PHP 5.4+ there is, in fact, a prefix:
Current info in PHP Docs:
Binary integer literals are available since PHP 5.4.0.
To use octal notation, precede the number with a 0 (zero). To use hexadecimal notation precede the number with 0x. To use binary notation precede the number with 0b.
Mar 24 ’10 at 11:31 (original answer):
I don’t think there is one. Prefix
0 if for octal and
0x is for hexadecimal.
From PHP docs:
Integer can be specified in decimal (base 10), hexadecimal (base 16), or octal (base 8) notation, optionally preceded by a sign (- or +).
To use octal notation, precede the number with a 0 (zero). To use hexadecimal notation precede the number with 0x.
Also, keep in mind that each hex digit represents 4 bits, so it’s easy to convert between binary notation and hex. The same is true for octal, but for various reasons it’s used less often in practice.