Reputation: 293
Hi i just want to know how works this operator in this case...
<html>
<head><title></title>
<script>
var ff=23|1|3|65|1|25;
//result 95
alert(ff);
why the result is 95?
</script></head>
</html>
Why the result is 95? what is the procceses?
Upvotes: 0
Views: 28
Reputation: 239443
|
stands for Bitwise OR operator. The result of bitwise or of all those numbers is 95.
Apply binary OR operation over all these numbers
0010111 - 23
0000001 - 1
0000011 - 3
1000001 - 65
0000001 - 1
0011001 - 25
-------
1011111 - 95
and the result would be 95. The Truth table for Bitwise OR is as follows
+-----------+
| | 0 | 1 |
-------------
| 0 | 0 | 1 |
-------------
| 1 | 1 | 1 |
-------------
You can even check the step-by-step results, like this
23 | 1
// 23
23 | 3
// 23
23 | 65
// 87
87 | 1
// 87
87 | 25
// 95
Upvotes: 2