Solved

Is this bitwise &?

Posted on 2011-02-15
8
366 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 74

Expert Comment

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

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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

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

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now