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. Operators-Description
()-Grouping ! ~ - Unary operators * / % + - Arithmetic operators << >> < > Logical shift and redirectional operators
& Bitwise and
^ Bitwise exclusive or |-Bitwise or = *= /= %= += -= &= ^= |= <<= >>= Assignment operators
, - separator
&& For using Multiple commands || For executing one from many commands
The above given were the operators available in Batch file programming for performing arithmetic and
logical operations. 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
10
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
No comments:
Post a Comment