开发者

Bitwise conversion of decimal to integer

I don't know if this is specif开发者_运维百科ic to JavaScript.

var pi = 3.14159265
alert(pi|0)

This will output 3.

Can someone explain what happens to the decimal fractions part during the bitwise OR operation?


The bitwise or operator only operates on integer types, so the fractional component is silently stripped off the number. A bitwise or with zero will always result in the other operand. Therefore, you get 3.


Bitwise operator only works on integers.

pi (3.14..) is converted to an INT which truncates the decimal places to 3.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜