ECMAScript 6 negative binary literal

后端 未结 1 704
眼角桃花
眼角桃花 2021-01-25 09:09

With EMCAScript6, I see there\'s a way to represent binary literals using the 0b or 0B prefix. I was experimenting with it, and couldn\'t find a way to

相关标签:
1条回答
  • 2021-01-25 10:02

    To input negative number just prefix your literal with - sign (unary minus operator):

    -0b11010 // -26
    

    Specification for binary literals is in section Numeric Literals.

    Relevant fragment:

    NumericLiteral :: (...) BinaryIntegerLiteral

    BinaryIntegerLiteral :: 0b BinaryDigits

    And BinaryDiggits are 0 and 1.

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