Why does OR 0 round numbers in Javascript?

前端 未结 3 1740
天命终不由人
天命终不由人 2021-01-21 02:06

I\'m under the impression that the Number type in Javascript stores any number, integer or float, according to the IEEE floating point standard. If so, then why does bitwise OR-

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-21 02:26

    Quote from MDN

    Bitwise operators treat their operands as a sequence of 32 bits (zeros and ones), rather than as decimal, hexadecimal, or octal numbers.

    If you didn't treat the numbers like this the bitwise ops wouldn't make much sense, which is why it is done

提交回复
热议问题