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
  • 623
  • 9
  • 20
  • 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
  • 741,623
  • 53
  • 500
  • 612
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
  • 715
  • 8
  • 19