Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Arduino operator


May 15, 2021 Arduino


Table of contents


An operator is a symbol that tells the compiler to perform a specific mathematical or logical function. The C language has rich built-in operators and provides the following types of operators:

  • Arithmetic Operators arithmetic operator
  • Comparison Operators comparison operator
  • Boolean Operators Boolean operator
  • Bitwise Operators bit operator
  • Compound Operators composite operator

Arithmetic operator

Assuming variable A is 10 and variable B is 20, then:

Example

The operator name The operator is short Describe Example
The assignment operator
= Store the value to the right of the equal sign in the variable to the left of the equal sign. A = B
Plus + The two operations add up A plus B will get 30
Minus sign - Subtract the second operand from the first operand A - B will result in -10
Multiplier * Multiply the two operations A :B will result in 200
Divide the sign / Divide the molecules by denominator B / A will result in 2
Modulus % The remaining number after the module operator and the integer are divided B % A will result in 0


Comparison operator

Assuming variable A is 10 and variable B is 20, then:

Example

The operator name The operator is short
Describe Example
Equals == Check that the values of the two operasts are equal, and if so, the condition is true. (A s b) is not true
Not equal to != Check that the values of the two operasts are equal, and that the conditions are true if the values are not equal. (A! . . B) is true
Less than < Check that the value of the left operance is less than the value of the right operast? (A slt; B) is true
Greater than > Check that the value of the left operance is greater than the value of the right operast? (A and B) is not true
Less than or equal to <= Check that the value of the left operance is less than or equal to the value of the right operast? (A -lt;?B) is true
Is greater than or equal to >= Check whether the value of the left operance is greater than or equal to the value of the right operans, and if so, the condition is true. (A and B) are not true


Boolean operator

Assuming variable A is 10 and variable B is 20, then:

Example

The operator name
The operator is short
Describe Example
and (and) && Is called a logical operator with . /b10> If both operations are non-zero, the condition is true. (A and B) is true
or(or) || Called a logical operator or. /b10> If neither of the two operasts is non-zero, the condition is true. (A || B) for the truth
Not (non) ! Called a logical operator non. /b10> The logical state used to reverse its operans. /b11> If the condition is true, the logical operator is not false. ! (A and B) is false


Bit operator

Assuming variable A is 60 and variable B is 13, then:

Example

The operator name
The operator is short
Describe Example
and (and) & If both operands exist at the same time, the binary AND operator copies one bit into the result. (A and B) will result in 12, i.e. 0000 1100
or(or) | If it exists in either operand, the binary OR operator copies one bit into the result. (A | B) will result in 61, i.e. 0011 1101
xor (alien) ^ If it exists in one of the operands but not both, the binary XOR operator copies one bit into the result. 49, i.e. 0011 0001, will be derived from (A-B).
Not (non) ~ The binary NOT operator is a binary operator with a "flip" bit effect. (-A) will result in -60, i.e. 1100 0011
shift left (left)
<< The binary left-shift operator. T he value of the left operans moves the number of digits specified by the right-hand operans to the left. A.lt;lt;2 will result in 240, or 1111 0000
shift right (right)
>> Binary right-shift operator. T he value of the left operans moves to the right the number of digits specified by the right-hand operans. A.gt;2 will result in 15, i.e. 0000 1111


The composite operator

Assuming variable A is 10 and variable B is 20, then:

Example

The operator name
The operator is short
Describe Example
Self-increase ++ Self-adding operator to increase the integer value by 1 You'll get 11
Self-reducing -- The self-subtract operator, which subtracts the integer value by 1 A-- 9 will be drawn
Composite plus
+= Add and assign operators. /b10> Assign the result of the right-hand operans plus the left-hand operans to the left-hand operans. The equivalent of B-A is B-B-A
Compound minus
-= Subtract and assign operators. /b10> Assign the result of the left operans minus the right-hand operans to the left- operans. B - - A is equivalent to B - B - A
Composite multiplicity
*= Multiply and assign operators. Multiply the right operans by the result of the left operans to the left operastr. B s A is equivalent to B s B s A
Composite divide
/= Divide and assign operators. Divide the left operans by the results of the right-hand operans and assign them to the left-hand operans. B /-A is equivalent to B-B/A
Composite modules
%= The mod and assignment operator. The module assignment of the two operasts is given to the left operator B % - A is equivalent to B - B % A
Composite by bit or |= A bit-by-bit or assignment operator A | s 2 and A s A | 2 Same
Composite by bit with
&= Bit-by-bit and assignment operators A and 2 are the same as A and A and 2