# TCL運算符

• 算術運算符
• 關係運算符
• 邏輯運算符
• 位運算符
• 三元運算符

+

A + B = 30

-

A - B = -10

*

A * B = 200

/

B / A = 2

%

B % A = 0

## 關係運算符

==

(A == B) 不爲 true.

!=

(A != B) 爲 true.

>

(A > B) 不爲  true.

<

(A < B) 爲 true.

>=

(A >= B) 不爲 true.

<=

(A <= B) 爲 true.

## 邏輯運算符

&&

(A && B) 爲 false.

||

(A || B) 爲 true.

!

!(A && B) 爲 true.

## 位運算符

p

q

p & q

p | q

p ^ q

0

0

0

0

0

0

1

0

1

1

1

1

1

1

0

1

0

0

1

1

A = 0011 1100

B = 0000 1101

-----------------

A&B = 0000 1100

A|B = 0011 1101

A^B = 0011 0001

&

(A & B) = 12, 也就是 0000 1100

|

(A | B) = 61, 也就是 0011 1101

^

(A ^ B) = 49, 也就是 0011 0001

<<

A << 2 = 240 也就是 1111 0000

>>

A >> 2 = 15 也就是 0000 1111

? :

Ternary

Unary

+ -

Right to left

Multiplicative

* / %

Left to right

+ -

Left to right

Shift

<< >>

Left to right

Relational

< <= > >=

Left to right

Bitwise AND

&

Left to right

Bitwise XOR

^

Left to right

Bitwise OR

|

Left to right

Logical AND

&&

Left to right

Logical OR

||

Left to right

Ternary

?:

Right to left