Pages

Batch Programming Lesson 3

Batch Operators


     Similar to other programming languages, batch program do support various operators for performing operations like arithmetic and logical operations, bitwise AND, OR, NOT, shifting and redirection operation and separators and grouping operators. Before all these going on if you not yet see my 1st and 2nd tutorial go and see them first to understand what is batch progamming.



Operators Description
() Grouping
!     ~     -  Unary operators 
*   /    %  +  -  Arithmetic operators 
<<    >>  <   >  Logical shift and re directional operators 
&  Bitwise and 
^  Bitwise exclusive or 
| Bitwise or 
=   *=   /=   %=   +=   -=   &=   ^=   |=   <<=   >>=  Assignment operators 
&&  For using Multiple commands

Let me brief you the operators with a small example,

Note : For performing arithmetic operations, the ‘SET’ command should be used along with the ‘/A’ switch.

For performing an addition operation on two integers, then I have to use the below command,

C:\>set /A 5 + 5


As you see in the above example, the ‘set /A’ is used for performing arithmetic operations like addition, subtraction, multiplication and division. The above example is used for performing an addition operation on two integer namely 5 and 5 and gives the output as ‘10’. Similarly you can use the other arithmetic operators.

Example:

The below command is used to subtract 5 from 10.
C:\>set /A 10-5
5

The below command is used finding the product between 5 and 5.
C:\>set /A 5*5
25

The below command is for dividing 10 by 5 and displays the output.
C:\>set /A 10/5
2

The below command is finding the remainder value and this operator is called modulo operator. In this example the remainder value obtained when 11 divided by 5 is 1 and is displayed as output.
C:\>set /A 11%5
1

Next Lesson  -  Operator precedence