curiouswebster
asked on
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
control.IsVisible = control.IsVisible & true;
I am at a loss as to what this means.
Does anyone know?
Thanks,
newbieweb
Yes, a single ampersand denotes bitwise-AND.
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;
control.IsVisible = !control.IsVisible;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I also concluded the code did nothing. Please respond now if you disagree...
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... = )
Is that line part of a larger block? Maybe it was intended to do something at some point, but is now redundant.
ASKER
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.
Thanks.
code taken form :http://weblogs.asp.net/alessandro/archive/2007/10/02/bitwise-operators-in-c-or-xor-and-amp-amp-not.aspx
regards.
Open in new window