Solved

Is this bitwise &?

Posted on 2011-02-15
8
370 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

862 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

23 Experts available now in Live!

Get 1:1 Help Now