Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

dos batch file bitwise and

Posted on 2013-01-23
3
Medium Priority
?
1,092 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 59

Accepted Solution

by:
Bill Prew earned 2000 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 59

Expert Comment

by:Bill Prew
ID: 38811288
Welcome.

~bp
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

927 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