


Introduction to the use of Javascript bitwise AND assignment operator (&=)_Basic knowledge
Javascript bitwise AND assignment operator (&=) sets the result of the bitwise AND operation between variable value and expression value. Variables and expressions are regarded as 32-bit binary values, and general expressions contain decimal integers. In this case, they need to be converted into the corresponding binary first, and then 0 is added forward to make up the 32 bits.
result &= [integer 2]
equivalent In
result = result & [integer 2]
& performs a 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.
位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 The binary value is 1001, and the 32-digit complement is 0000000000000000000000000000100 1
var expr1 = 9;
// 5 is 00000000000000000000000000000101
var expr2 = 5;
/*
00000000000000000000000000001001
&
000000000000000000000000000000101
=
00000000000000000 00000000000001
=
1
*/
var result = expr1 & expr2 ;
alert(result);
//pop up【1】
expr1 &= expr2;
alert(expr1);
// Pop up【1】
JavaScript assignment operators and expressions
JavaScript assignment operators are responsible for assigning values to variables. JavaScript assignment operators include =, =, -=, *=, / =, %=
An expression that is connected with the assignment operator and the operand (operand) and conforms to the regular JavaScript syntax is called a JavaScript assignment expression.
JavaScript assignment operator and assignment expression syntax
var i =a;
= -- assignment operator
The meaning of the above expression is: change i The value obtained by adding a is assigned to variable i.
JavaScript assignment operators and assignment expressions
Operator | = |
= |
-= |
*= |
/= |
%= |
---|
运算符 | = |
= |
-= |
*= |
/= |
%= |
---|---|---|---|---|---|---|
名称 | 赋值运算符 | 加法赋值运算符 | 减法赋值运算符 | 乘法赋值运算符 | 除法赋值运算符 | 模赋值运算符(求余赋值运算符) |
表达式 | i=6 | i =5 | i-=5 | i*=5 | i/=5 | i%=5 |
示例 | var i=6; | i =5; | i-=5; | i*=5; | i/=5; | i%=5; |
i的结果 | 6 | 11 | 1 | 30 | 1.2 | 1 |
等价于 | i=i 5; | i=i-5; | i=i*5; | i=i/5; | i=i%5; |
Copy code

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In Python, "+=" refers to the "addition assignment" operator, which is a type of assignment operator. Its function is to perform an addition operation first, and then assign the result to the variable on the left side of the operator; the syntax is "x += y", the equivalent form is "x = x + y". The "+=" operator can only assign values to existing variables, because the variable itself needs to participate in the operation during the assignment process. If the variable is not defined in advance, its value is unknown and cannot participate in the operation.

Introduction to python operators Operators are special symbols or keywords used to perform operations between two or more operands. Python provides a variety of operators covering a wide range of uses, from basic mathematical operations to complex data manipulation. Mathematical operators Mathematical operators are used to perform common mathematical operations. They include: operator operation examples + addition a + b - subtraction a-b * multiplication a * b / division a / b % modulo operation (take the remainder) a % b ** power operation a ** b // integer division (discard the remainder) a//b Logical Operators Logical operators are used to concatenate Boolean values and evaluate conditions. They include: operator operations examples and logical and aandbor logical or aorbnot logical not nota comparison operations

The Secret Garden of Operators Python operators are symbols or keywords used to perform various operations. They enable developers to express complex logic concisely and clearly and improve code efficiency. Python provides a wide range of operator types, each with its specific purpose and usage. Logical Operators Logical operators are used to combine Boolean values and perform logical operations. The main ones are: and: Returns the Boolean value True, if all operands are True, otherwise it returns False. or: Returns a Boolean value True if any operand is True, otherwise returns False. not: Negate the Boolean value, change True to False, and change False to True. Demo code: x=Truey

Python operators are a key component of the programming language, enabling developers to perform a wide range of operations, from simple arithmetic to complex bit manipulation. Mastering the syntax, semantics, and functionality of operators is essential to using Python effectively. Arithmetic Operators Arithmetic operators are used to perform basic arithmetic operations. They include addition (+), subtraction (-), multiplication (*), division (/), modulo (%), exponentiation (**), and floor division (//). The following example demonstrates the use of arithmetic operators: >>a=10>>b=5#Addition c=a+bprint(c)#Output: 15#Subtraction c=a-bprint(c)#Output: 5#Multiplication c=a*bprint(c)#output

Let us consider that in C or C++, there is a similar statement: c=a+++b; So what is the meaning of this line of code? Okay, let a and b be 2 and 5 respectively. This expression can be viewed as two different types. c=(a++)+bc=a+(++b) has post-increment operator and pre-increment operator. How they are used depends on how they are used. There are two basic concepts. Priority and associativity. Now if we check the expression from left to right, the result will be these two. c=(a++)+b→2+5=7c=a+(++b)→2+6=8 Now let’s check which option is selected by the compiler - example code #include<io

Python operators are special symbols or words used to perform specific operations on values or to combine values. They are the fundamental building blocks of programming languages and are key to understanding and writing efficient code. Arithmetic Operators Arithmetic operators are used to perform basic mathematical operations such as addition, subtraction, multiplication, division, and remainder. The following are the most commonly used arithmetic operators: +Addition-Subtraction*Multiplication/Division%Remainder Example: x=10y=5print(x+y)#Output: 15print(x-y)#Output: 5print(x*y)#Output :50print(x/y)#Output: 2.0print(x%y)#Output: 0 Comparison Operator The comparison operator is used to compare two values and return a Boolean value (True

First, let's learn about logical operators. Logical Operators These are used to logically combine two (or more) expressions. They are logical AND (&&), logical OR (||) and logical NOT (!) logical AND (&&) exp1exp2exp1&&exp2TTTTFFFTFFFF logical OR (||) exp1exp2exp1||exp2TTTTFTFTTFFF logical NOT (!) exp!expTTFT Operator Description Example a= 10,b=20,c=30 output&&logical AND(a>b)&&(a<c)(10>

PHP modular equals refers to "%=", which is an extended assignment operator, which means to perform the modulo operation first, and then assign the result to the variable on the left side of the operator; the syntax is "x %= y", the equivalent form is "x = x % y". The extended assignment operator combines = with other operators (including arithmetic operators, bitwise operators and logical operators) to expand it into a more powerful assignment operator; the expanded assignment operator will make the assignment expression Writing is more elegant and convenient.
