Javascript bitwise AND operator (& amp;) is used to perform bitwise "and" operations on two 32-bit expressions. Generally, the expressions are decimal integers, in this case, you need to first convert it to the corresponding binary, and then add 0 to the forward to supplement the 32-bit
The Code is as follows:
Result = [integer 1] & [integer 1]
& Perform the bitwise "and" operation on each bit of two 32-bit expressions. If both bits are 1, the result is 1. Otherwise, the result is 0.
Bit 1 |
Bits 2 |
Bitwise AND |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
The following example shows how to use the & bitwise AND operator and the & = bitwise AND value assignment operator:
The Code is as follows:
// 9 the binary value is 1001, and the 32-bit complement value is 00000000000000000000000000001001.
Var expr1 = 9;
// 5 is 00000000000000000000000000000101
Var expr2 = 5;
/*
00000000000000000000000000001001
&
00000000000000000000000000000101
=
00000000000000000000000000000001
=
1
*/
Var result = expr1 & expr2;
Alert (result );
// [1] is displayed]
Expr1 & = expr2;
Alert (expr1 );
// [1] is displayed]