tags:

views:

181

answers:

3

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

A: 

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.

codaddict
+2  A: 

Writing binary is not something that's often necessary, in PHP ; so 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, 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.

Pascal MARTIN
Sorry to hear that...But you are the first to give an alternative solution:)
+1  A: 

Check the manual: PHP only supports decimal, hexadecimal and octal integer notation, but you can use bindec() instead.

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.

Christoph