Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Is this bitwise &?

Posted on 2011-02-15
8
Medium Priority
?
381 Views
Last Modified: 2012-05-11
I see a line of code in a woring C# program that looks like:

control.IsVisible = control.IsVisible & true;

I am at a loss as to what this means.

Does anyone know?

Thanks,
newbieweb

0
Comment
Question by:newbieweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 6

Expert Comment

by:loopfinity
ID: 34901740
this is binary end operator.
code taken form :http://weblogs.asp.net/alessandro/archive/2007/10/02/bitwise-operators-in-c-or-xor-and-amp-amp-not.aspx

regards.
protected void Page_Load(object sender, EventArgs e)
{
byte a = 7;
byte b = 9;
int orComputed = a & b;
Response.Write(string.Format("<br />{0} & {1} Result :{2}", a, b, orComputed));
}

Output is :
7 & 9 Result :1

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34901809
Yes, a single ampersand denotes bitwise-AND.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34901845
To go further, the expression sets the value of IsVisible to true if IsVisible is false, and false if IsVisible is true. It basically flips the value of IsVisible, which could also be accomplished via a NOT:

control.IsVisible = !control.IsVisible;
0
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 34901901
No it doesn't. XOR would have the effect of flipping the bit, AND has the effect of setting it to its current value. So that snippet would appear to not actually do anything.
0
 

Author Comment

by:newbieweb
ID: 34902181
I also concluded the code did nothing.  Please respond now if you disagree...
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34903744
Well...   do  I feel sheepish....  on second glance (and thx to carl_tawn's dilligence) I agree, it does not flip the value. That explains why they won't let me play with the bits at work...     =  )
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34904278
Is that line part of a larger block? Maybe it was intended to do something at some point, but is now redundant.
0
 

Author Closing Comment

by:newbieweb
ID: 34906331
I'm not sure about the rest of the code. I was asked to explain this bizarre line, and also concluded it did nothing.

Thanks.
0

Featured Post

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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