JavaScript according to the position and assignment operator (& =), set the result of the "and" operation of the variable value and the expression value. The variables and expressions are regarded as a 32 -bit binary value, and the general expression is a decimal integer. At this time, you need to convert it to the corresponding binary, then add 0 forward, and make up for 32 -bit.
Copy code code as follows:
result & = [Indica 2]
Equivalent
result = result & 【integer 2】
& Perform each bit of two 32 -bit expressions "and" with "operations. If both bits are 1, the result is 1. Otherwise, the result is 0.
| 1st | Position 2 | Position and |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 1 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
The following example demonstrates how to use & bits and operators and & = according to bit and assignment operators:
Copy code code as follows:
// 9 binary is 1001, and 32 -bit is 000000000000000000000000001001
var expr1 = 9;
// 5 is 000000000000000000000000000101
var expr2 = 5;
/*
0000000000000000000000001001
&
0000000000000000000000000101
=
0000000000000000000000000001
=
1
*/
var result = expr1 & expr2;
alert (result);
// Plug it [1]
expr1 & = expr2;
alert (expr1);
// Plug it [1]
JavaScript assignment and expression
JavaScript assignment operator is responsible for assigning a variable. JavaScript assignment operator includes =,+=,-=,*=,/=,%=,%=
Connect with the assignment operator to the operation object (operating number), and the JavaScript syntax that conforms to the rules is called JavaScript assignment expression.
JavaScript assignment and assignment symbolic syntax
var I+= A;
+= - Assignment operator
The significance of the above expression is: add the value of I to A with A to give variable i.
JavaScript assignment and assignment expression and assignment expression
| Operator | = | += | -= | *= | /= | %= |
|---|---|---|---|---|---|---|
| name | Assignment operator | Add method to assign value operator | Subtraction assignment operator | Method assignment operator | Except the method of assignment of the method | Model compartment operator (find the residual assignment operator) |
| expression | i = 6 | i+= 5 | I- = 5 | I*= 5 | I/= 5 | I%= 5 |
| Exemplary example | var I = 6; | i+= 5; | I- = 5; | i*= 5; | I/= 5; | i%= 5; |
| I result | 6 | 11 | 1 | 30 | 1.2 | 1 |
| Equivalent | i = i+5; | i = i-5; | i = i*5; | i = I/5; | i = i%5; |
Example explanation
There is a essential difference between the self -increasing operational formula and the rear self -incremental arithmetic. The same points are to add 1 for themselves. The difference is that the previous self -incremental calculation is added first, and then the value of the operation number is used. The addition of the additional operation is the value of the operating number first, plus 1. For example:
Copy code code as follows:
var a;
var I = 6;
// (Previous addition) After 1 plus 1, i equal to 7, and give the value to A, so A is equal to 7
a = ++ i;
document.write (i);
document.write (a);
i = 6;
// (later plus) give A value A, so A is equal to 6, and finally I plus 1, i equal to 7
a = i ++;
document.write (i);
document.write (a);
result:
Copy code code as follows:
7
7
7
6