Solved

dos batch file bitwise and

Posted on 2013-01-23
3
844 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 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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
Comment Utility
Thanks!
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Welcome.

~bp
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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