Solved

Is this bitwise &?

Posted on 2011-02-15
8
372 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Media.Imaging 1 18
How do I bind WPF Telerik radMenuItems to commands in XAML ControlTemplate ? 1 15
Expression Evaluater 3 25
Sending receiving text messages in vb.net 15 34
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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