What's the prefix for binary in PHP?

前端 未结 4 842
南方客
南方客 2020-12-03 02:31

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

4条回答
  •  我在风中等你
    2020-12-03 03:21

    From PHP 5.4+ there is, in fact, a prefix: 0b.

    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.

提交回复
热议问题