result = [Integer 1] & [Integer 1]
& 对两个 32 位表达式的每一个位执行按位“与”运算。 如果两个位均为 1,则结果是 1。 否则,结果为 0。
位1 |
位2 |
位与 |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
The following example demonstrates how to use the & bitwise AND operator and the &= bitwise AND assignment operator:
// 9 Binary is 1001, the complement of 32 bits is 00000000000000000000000000001001
var expr1 = 9;
// 5 is 000000000000000000000000000101
var expr2 = 5;
/*
0000000000000000000000000001001
& >00000000000000000000000000000101
=
000000000000000000000000000000001
=
1
*/
var result = expr1 & expr2;
alert(result);
// popup【1】
expr1 &= expr2;
alert(expr1);
//pop-up【1】