Batch-script-operators

提供:Dev Guides
移動先:案内検索

バッチスクリプト-オペレーター

演算子は、特定の数学的または論理的な操作を実行するようコンパイラーに指示する記号です。

バッチスクリプトでは、次の種類の演算子が可能です。

  • 算術演算子
  • 関係演算子
  • 論理演算子
  • 割り当て演算子
  • ビットごとの演算子

算術演算子

バッチスクリプト言語は、通常の算術演算子を任意の言語としてサポートします。 使用可能な算術演算子は次のとおりです。

link:/batch_script/batch_script_arithmetic_operators [例を表示]

Operator Description Example
PLUS Addition of two operands 1 PLUS 2 will give 3
Subtracts second operand from the first 2 − 1 will give 1
* Multiplication of both operands 2* 2 will give 4
/ Division of the numerator by the denominator 3/2 will give 1.5
% Modulus operator and remainder of after an integer/float division 3 % 2 will give 1

関係演算子

関係演算子は、オブジェクトの比較を許可します。 以下は利用可能な関係演算子です。

link:/batch_script/batch_script_relational_operators [例を表示]

Operator Description Example
EQU Tests the equality between two objects 2 EQU 2 will give true
NEQ Tests the difference between two objects 3 NEQ 2 will give true
LSS Checks to see if the left object is less than the right operand 2 LSS 3 will give true
LEQ Checks to see if the left object is less than or equal to the right operand 2 LEQ 3 will give true
GTR Checks to see if the left object is greater than the right operand 3 GTR 2 will give true
GEQ Checks to see if the left object is greater than or equal to the right operand 3 GEQ 2 will give true

論理演算子

論理演算子は、ブール式を評価するために使用されます。 以下は利用可能な論理演算子です。

バッチ言語には、AND、OR、XORなどのブール論理演算子の完全なセットが装備されていますが、これは2進数専用です。 TRUEまたはFALSEの値もありません。 条件に使用できる唯一の論理演算子はNOT演算子です。

link:/batch_script/batch_script_logical_operators [例を表示]

Operator Description
AND This is the logical “and” operator
OR This is the logical “or” operator
NOT This is the logical “not” operator

割り当て演算子

バッチスクリプト言語は、代入演算子も提供します。 使用可能な割り当て演算子は次のとおりです。

link:/batch_script/batch_script_assignment_operators [例を表示]

Operator Description Example
PLUS= This adds right operand to the left operand and assigns the result to left operand

Set/A a = 5

+ = 3

出力は8になります

-= This subtracts the right operand from the left operand and assigns the result to the left operand

Set/A a = 5

a-= 3

出力は2になります

*= This multiplies the right operand with the left operand and assigns the result to the left operand

Set/A a = 5

a * = 3

出力は15になります

/= This divides the left operand with the right operand and assigns the result to the left operand

Set/A a = 6

a/= 3

出力は2になります

%= This takes modulus using two operands and assigns the result to the left operand

Set/A a = 5

a%= 3

出力は2になります

ビット演算子

ビット単位の演算子もバッチスクリプトで使用できます。 使用可能な演算子は次のとおりです。

リンク:/batch_script/batch_script_bitwise_operators [例を表示]

Operator Description
& This is the bitwise “and” operator
This is the bitwise “or” operator ^

以下は、これらの演算子を示す真理値表です。

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