473,395 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

problem with logical operator

Hi,
I have a value that contains flags that I must get using a bitmask. I tryied
with the && operator, but the compiler outputs this error :

Operator '&&' cannot be applied to operands of type 'int' and 'int'

The code is the following :

// MASKS.Insert = 2
if (_RightMask && (int)MASKS.Insert)
{
do something
}

I tried with and without the cast (int), but nothing works... Am I missing
something? it seems to be the right way of doing it but the compiler does
not allow it.

Thanks

ThunderMusic
Jan 19 '06 #1
2 4095
Use & instead of &&.

"ThunderMusic" wrote:
Hi,
I have a value that contains flags that I must get using a bitmask. I tryied
with the && operator, but the compiler outputs this error :

Operator '&&' cannot be applied to operands of type 'int' and 'int'

The code is the following :

// MASKS.Insert = 2
if (_RightMask && (int)MASKS.Insert)
{
do something
}

I tried with and without the cast (int), but nothing works... Am I missing
something? it seems to be the right way of doing it but the compiler does
not allow it.

Thanks

ThunderMusic

Jan 19 '06 #2
As Sergey says; use &.

& and | are the C# bitwise operators. They are also overloaded to be the C#
non-short-circuit logical operators. (&& and || are the short-circuit
logical operators.)

(In VB, "And" and "Or" are both the bitwise operators and non-short-circuit
logical operators, while "AndAlso" and "OrElse" are the short-circuit logical
operators).

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter

"ThunderMusic" wrote:
Hi,
I have a value that contains flags that I must get using a bitmask. I tryied
with the && operator, but the compiler outputs this error :

Operator '&&' cannot be applied to operands of type 'int' and 'int'

The code is the following :

// MASKS.Insert = 2
if (_RightMask && (int)MASKS.Insert)
{
do something
}

I tried with and without the cast (int), but nothing works... Am I missing
something? it seems to be the right way of doing it but the compiler does
not allow it.

Thanks

ThunderMusic

Jan 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jay Moore | last post by:
If any of you happened to read my earlier posts, I had a dilemma with creating an efficient method of limiting access to data for my users and subusers. My heirarchy looks like this: Admins...
3
by: Nagib Abi Fadel | last post by:
Is there a XOR logical operator in Postgresql, or a function for XOR ?? I only found in the docs a Binary XOR (#). I need to do the following checkup: (field1 is NULL XOR field2 is NULL XOR...
80
by: Christopher Benson-Manica | last post by:
Of course one can get the effect with appropriate use of existing operators, but a ^^ operator would make for nice symmetry (as well as useful to me in something I'm working on). Am I the only one...
8
by: Chua Wen Ching | last post by:
Hi, I had some beginner questions. Do we need Shift << >> or Logical AND OR XOR operator in our daily programming? I am not sure why i need to use it? I had some samples of c# codes using it. ...
23
by: Cor | last post by:
Hi group, A question to the group, would it not be for a lot of the users better when there was beside "Option strict on" an "Option logical Strict on". I was automaticaly writting...
21
by: Mike | last post by:
I am having a problem getting AND to work. I have a MySQL database field defined as varbinary(8) with X00 in it. Then I have define statements with X01 in it. define('CERTACCESS_MEDALS', x01); ...
32
by: paul | last post by:
HI! I keep on getting this error and I have tried different things but I am not sure how to send the expiring date. The error that I am getting in Firefox 1.5 is "Error: expires.toGMTString is...
9
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T');...
3
by: gallows | last post by:
Hi, I wondering if there is a standard specification for evalutation of logical expressions. For instance: if (p != NULL && strlen(p) x ) do_something(); If p is actually NULL, should this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.