0

Please describe how does 5.55 | 0 produces 5 in JavaScript. I want to know what is happening in this bitwise operating. Thanks!

Naveen
  • 573
  • 7
  • 18
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_OR – Bergi Jun 07 '14 at 17:01

2 Answers2

2

The bitwise operators in Javascript automatically coerce their arguments to 32-bit integer values by dropping the fraction and any high-order bits beyond 32. So

5.55 | 0

is treated like:

5 | 0
Barmar
  • 669,327
  • 51
  • 454
  • 560
1

The operands of bitwise operations are always converted to signed 32-bit integers in big-endian order and in two's complement format.

That would be

    00000000000000000000000000000101
or  00000000000000000000000000000000
------------------------------------ 
    00000000000000000000000000000101
user2291758
  • 665
  • 8
  • 19