|
Answer» Is there an AND OPERATOR for batch FILE?
Any comment or suggestions would be greatly appreciated. thank you.bitwise AND operator is &
Code: [Select] SET /A expression
The /A switch specifies that the string to the right of the equal sign is a NUMERICAL expression that is evaluated. The expression evaluator is pretty simple and supports the following operations, in decreasing order of precedence:
() - grouping ! ~ - - unary operators * / % - arithmetic operators + - - arithmetic operators << >> - logical shift & - bitwise and ^ - bitwise exclusive or | - bitwise or = *= /= %= += -= - assignment &= ^= |= <<= >>= , - expression separator
If you use any of the logical or modulus operators, you will need to enclose the expression string in quotes. I apologize if this sounds stupid. I wrote a small program to test it out but it does not work with an AND operand, “&” as you have indicated. It does not display anything.
What am I doing wrong? Thanks (in ADVANCE)
Here’s the code:
@ECHO OFF
set /a five=5 set /a three=3
if ((5 equ %five%) & (3 equ %three%)) (echo TRUE) else (echo FALSE) pause
That is a logical AND. (Not bitwise and) Not available directly in batch. Has to be simulated.
Code: [Select]if 5 equ %five% if 2 equ %three% (echo true) else (echo false)
|