# Arduino - 运算符

• 算术运算符
• 比较运算符
• 布尔运算符
• 按位运算符
• 复合运算符

## 算术运算符

A - B=-10

A * B=200

B/A=2

void loop () {
int a = 9,b = 4,c;
c = a + b;
c = a - b;
c = a * b;
c = a / b;
c = a % b;
}
a + b=13
a - b=5
a * b=36
a/b=2
Remainder when a divided by b=1

## 比较运算符

void loop () {
int a = 9,b = 4
bool c = false;
if(a == b)
c = true;
else
c = false;

if(a != b)
c = true;
else
c = false;

if(a < b)
c = true;
else
c = false;

if(a > b)
c = true;
else
c = false;

if(a <= b)
c = true;
else
c = false;

if(a >= b)
c = true;
else
c = false;
}
c=false
c=true
c=false
c=true
c=false
c=false

## 布尔运算符

and&&称为逻辑AND运算符。 如果两个操作数都不为零,则条件为真。(A && B) is true
or||称为逻辑或运算符。 如果两个操作数中的任何一个都不为零,则条件为真。(A || B) is true
not!称为逻辑非运算符。 用于反转其操作数的逻辑状态。 !(A && B) is false
void loop () {
int a = 9,b = 4
bool c = false;
if((a > b)&& (b < a))
c = true;
else
c = false;

if((a == b)|| (b < a))
c = true;
else
c = false;

if( !(a == b)&& (b < a))
c = true;
else
c = false;
}
c=true
c=true
c=true

## 按位运算符

and&如果两个操作数中都存在二进制AND运算符,则会将一位复制到结果中。(A & B)=12 which is 0000 1100
or|二进制或运算符将复制一个位。(A | B)=61 which is 0011 1101
xor^二进制XOR运算符将复制该位。(A ^ B)=49 which is 0011 0001
not~二进制补码运算符是一元的。(~A )=-60 which is 1100 0011
shift left<<二进制左移运算符。 A << 2=240 which is 1111 0000
shift right>>二进制右移运算符。 A >> 2=15 which is 0000 1111
void loop () {
int a = 10,b = 20
int c = 0;
c = a & b ;
c = a | b ;
c = a ^ b ;
c = a ~ b ;
c = a << b ;
c = a >> b ;
}
c=12
c=61
c=49
c=-60
c=240
c=15

## 复合运算符

increment++递增运算符,将整数值加一A++=11
decrement--递减运算符,将整数值减一A--=9
compound addition+=相加AND赋值运算符,它将右操作数添加到左操作数,并将结果分配给左操作数B += A is equivalent to B=B+ A
compound subtraction-=相减AND赋值运算符,它从左侧操作数中减去右侧操作数,并将结果分配给左侧操作数B -= A is equivalent to B=B - A
compound multiplication*=相乘AND赋值运算符,它将右操作数与左操作数相乘并将结果分配给左操作数B*= A is equivalent to B=B* A
compound division/=相除和赋值运算符,它将左操作数除以右操作数,并将结果分配给左操作数B /= A is equivalent to B=B/A
compound modulo%=模和赋值运算符,它使用两个操作数取模,并将结果分配给左操作数B %= A is equivalent to B=B % A
compound bitwise or|=按位或运算符和赋值运算符A |= 2 is same as A=A | 2
compound bitwise and&=按位与赋值运算符A &= 2 is same as A=A & 2
void loop () {
int a = 10,b = 20
int c = 0;

a++;
a--;
b += a;
b -= a;
b *= a;
b /= a;
a %= b;
a |= b;
a &= b;
}
a=11
a=9
b=30
b=10
b=200
b=2
a=0
a=0
a=30

Java并发编程实战 -〔王宝令〕

Spark核心原理与实战 -〔王磊〕