Solved

# Simulating the == operator using the bitwise operators.

Posted on 2006-10-19

I would like to know how to simulate the == operator using the bitwise &, |, ~ and ^ operators in the

set /A expression= (some expression)

command.

Specifically, I want to simulate the if stmt condition: if (j==4)&&(option==1) { do something } . But I don't know of a way in DOS to combine two conditions. I tried: if %j%==4&%option%==1 , but this doesn't work. I figured that if did something like this:

set /A answer1=j&4 ::wanted to get 1 or 0 based on j and 4s equality, but doesn't work because I get 4 if they

::are equal and I can't get zero unless j is zero.

set /A answer2=option&1::wanted the same thing to happen here, which is easier because if option is one

::then the answer2 becomes 1, but if the option isn't one it won't be zero unless option is zero

:: then I compare answer2 and answer1 based on the fact they should be 1 or 0.

if %answer1%==%answer2% { do something}