473,513 Members | 13,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

bitwise logical operations

Hello all,

In VB6 I'm able to do the following:

If (intValue And 64) = 64 Then
...
do something here
...
End If

where intValue is for examle 4160 (to satisfy the condition)

if i have a C# consolle application with:
Console.WriteLine(4160 & 64)
I will get 64 as a result - as expected, but how do I write the "If "test
with an integer variable passed in??
writting the following:
if (4160 & 64 == 64)
{ ...
do something here
...
}

I keep getting error:
Operator '&' cannot be applied to operands of type 'int' and 'bool'

Thanks in advance
Filip
Nov 16 '05 #1
3 6508
"Filip Kratochvil" <fi****@iname.com> wrote in message news:Oi**************@TK2MSFTNGP09.phx.gbl...
In VB6 I'm able to do the following:

If (intValue And 64) = 64 Then : : if (4160 & 64 == 64) : : I keep getting error:
Operator '&' cannot be applied to operands of type 'int' and 'bool'


Just like in VB.NET, Flip, the associativity of the equality operator
supercedes the logical-AND (in this context, it assumes there are
two terms, 4160 (ie, true) and 64 == 64 (ie, true)).

What is needed is a pair of parenthesis (which will force the & to
get interpreted as a bitwise-AND, rather than a logical-AND.

int someInt = 4160;
if ( ( someInt & 64 ) == 64 ) {
// . . . do something . . .
}

Derek Harmon
Nov 16 '05 #2
Derek
Thanks for the quick reply
Filip

"Derek Harmon" <lo*******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"Filip Kratochvil" <fi****@iname.com> wrote in message

news:Oi**************@TK2MSFTNGP09.phx.gbl...
In VB6 I'm able to do the following:

If (intValue And 64) = 64 Then

: :
if (4160 & 64 == 64)

: :
I keep getting error:
Operator '&' cannot be applied to operands of type 'int' and 'bool'


Just like in VB.NET, Flip, the associativity of the equality operator
supercedes the logical-AND (in this context, it assumes there are
two terms, 4160 (ie, true) and 64 == 64 (ie, true)).

What is needed is a pair of parenthesis (which will force the & to
get interpreted as a bitwise-AND, rather than a logical-AND.

int someInt = 4160;
if ( ( someInt & 64 ) == 64 ) {
// . . . do something . . .
}

Derek Harmon

Nov 16 '05 #3
What your running into is operator precedence...
Try this and it should work...
if ((int)(number & 64) == 64)

Filip Kratochvil wrote:
Hello all,

In VB6 I'm able to do the following:

If (intValue And 64) = 64 Then
...
do something here
...
End If

where intValue is for examle 4160 (to satisfy the condition)

if i have a C# consolle application with:
Console.WriteLine(4160 & 64)
I will get 64 as a result - as expected, but how do I write the "If "test
with an integer variable passed in??
writting the following:
if (4160 & 64 == 64)
{ ...
do something here
...
}

I keep getting error:
Operator '&' cannot be applied to operands of type 'int' and 'bool'

Thanks in advance
Filip


--
Regards,
Dilip Krishnan
MCAD, MCSD.net
dilipdotnet at apdiya dot com
Nov 16 '05 #4

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

Similar topics

9
2519
by: Michael B. Trausch | last post by:
I have a question regarding bitwise operators, I've been trying to figure this out for about two days now, and I just can't seem to get it. What I'm trying to do is use a variable to hold a bitmask...
7
4502
by: Jerry | last post by:
I want an algorithm that do arithmetic operations(divide,mutiply,add etc.)just using bitwise operators:<<,>>,&,|,^; For example,how "a/10" can be implemented. I just want a hint. Thanks.
3
736
by: Filip Kratochvil | last post by:
Hello all, In VB6 I'm able to do the following: If (intValue And 64) = 64 Then ... do something here ... End If
8
6924
by: Paul E Collins | last post by:
Suppose I have a few Keys objects: Keys k1 = Keys.V; // V Keys k2 = Keys.Control | Keys.V; // Ctrl+V Keys k3 = Keys.Shift | Keys.J; // Shift+J I need to determine which of these include the...
9
7020
by: Christopher Weaver | last post by:
I know that the bitwise AND of 8 and 4 will return 0 or false and the bitwise AND of 8 and 9 will return 1 or true but I don't know how to write the synax for it in C#. I have a value that ranges...
10
2147
by: Emilio | last post by:
Do I use 'or' for bitwise operations where in c# I use | ?
1
1404
by: S Shulman | last post by:
Hi I am looking for a sample of code that sets and reads individual bits within an Integer Thank you, Shmuel Shulman SBS Technologies LTD
3
12483
by: shdwsclan | last post by:
I am native to various languages but bitwise operators just kill me. I see how much I take object oriented languages for granted. I like all the other c derivitives but ANSI C is making me loose my...
45
5240
by: Carramba | last post by:
Hi! I now that I can't do straight forward any bitwise operation on float (double etc..). But I wondering what is the easiest/best way to do this? I was thinking if I have float x=1.1111 so I can...
29
5913
by: Carl Banks | last post by:
Anyone with me here? (I know the deadline for P3 PEPs has passed; this is just talk.) Not many people are bit-fiddling these days. One of the main uses of bit fields is flags, but that's not...
0
7254
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
7153
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
7373
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
7432
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...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.