What does a leading zero do for a php int?

前端 未结 4 1702
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 02:42
echo(073032097109032116104101032118101114121032109111100101108032111102032097032109111100101114110032109097106111114032103101110101114097108046);

E

相关标签:
4条回答
  • 2020-12-02 03:06

    If you use a leading zero, the number is interpreted by PHP as an octal number. Thus, a 9 is not a valid part of the number and the parser stops there:

      0730320 (base 8)
    =  7 * 8^5 + 3 * 8^4 + 3 * 8^2 + 2 * 8^1
    =  7 * 32768 + 3 * 4096 + 3 * 64 + 2 * 8 (base 10)
    =  241872 (base 10)
    
    0 讨论(0)
  • 2020-12-02 03:10

    A leading zero indicates an octal integer value

    0 讨论(0)
  • 2020-12-02 03:12

    Manual:

    Warning

    If an invalid digit is given in an octal integer (i.e. 8 or 9), the rest of the number is ignored.

    Example #2 Octal weirdness

    <?php
    var_dump(01090); // 010 octal = 8 decimal
    ?>
    

    So your number gets cut off after 0730320, which is 241872 in decimal.

    0 讨论(0)
  • 2020-12-02 03:15

    010 gives you 8 (octal number)
    0x10 gives you 16 (hexadecimal number)

    0 讨论(0)
提交回复
热议问题