bitmask manipulation

M

Mark Allison

Hi,

Total newbie here, I'm trying to examine a bitmask which is passed into
my app as a string. I convert it to int, and try and process it. I got
the following code:

//dbStatus current is a string
int idbStatus = Convert.ToInt32(dbStatus);
string dbStatusText = string.Empty;

if (idbStatus && 1 == 1) // error on this line
{
dbStatusText = dbStatusText + "autoclose";
}

Error message is:
Operator '&&' cannot be applied to operands of type 'int' and 'bool'

Ideas? Thanks. Any good URLs for bitmask manipulation would be great!

--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
 
R

Robert Jordan

Mark said:
Hi,

Total newbie here, I'm trying to examine a bitmask which is passed into
my app as a string. I convert it to int, and try and process it. I got
the following code:

//dbStatus current is a string
int idbStatus = Convert.ToInt32(dbStatus);
string dbStatusText = string.Empty;

if (idbStatus && 1 == 1) // error on this line

if ((idbStatus & 1) == 1)

&& - bool AND operator
& - bitwise AND operator

the braces are required because "&" has a lower precedence
then "==".

bye
Rob
 
P

Paul E Collins

Mark Allison said:
if (idbStatus && 1 == 1) // error on this line
[...]
Error message is:
Operator '&&' cannot be applied to operands of
type 'int' and 'bool'

The bitwise AND operator is a single &.

P.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top