Solved

dos batch file bitwise and

Posted on 2013-01-23
3
869 Views
Last Modified: 2013-01-23
Hi Experts,

I'm trying to do a simple bitwise and in dos.  The docs say that & is the bitwise character, but when I write:

      if 1 & 1==1 echo hello

I get the following error:

"& was unexpected at this time."

Any ideas how to check a mask on a variable in dos?  (if $myvar$ & 1 == 1)

Thanks!
Mike
0
Comment
Question by:thready
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 38810487
You will need to use the & in a SET /A statement, and since it's a special character to the command interpreter you need to quote it, or escape it.

So, you first set a variable to the result of the "AND", and then test the result, for example:

set /A "Test=15 & 1"
if %Test% == 1 echo hello


this will also work:

set /A Test=15 ^& 1
if %Test% == 1 echo hello


but this will not:

set /A Test=15 & 1
if %Test% == 1 echo hello


~bp
0
 
LVL 1

Author Closing Comment

by:thready
ID: 38810496
Thanks!
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 38811288
Welcome.

~bp
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now