• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

Is this bitwise &?

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
newbieweb
Asked:
newbieweb
  • 3
  • 2
  • 2
  • +1
1 Solution
 
loopfinityCommented:
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
 
käµfm³d 👽Commented:
Yes, a single ampersand denotes bitwise-AND.
0
 
käµfm³d 👽Commented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Carl TawnSystems and Integration DeveloperCommented:
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
 
newbiewebSr. Software EngineerAuthor Commented:
I also concluded the code did nothing.  Please respond now if you disagree...
0
 
käµfm³d 👽Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
Is that line part of a larger block? Maybe it was intended to do something at some point, but is now redundant.
0
 
newbiewebSr. Software EngineerAuthor Commented:
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now