Asked • 05/12/19

C# & operator clarification?

I saw a couple of questions here about the diference between && and & operators in C#, but I am still confused how it is used, and what outcome results in different situations. For example I just glimpsed the following code in a project bMyBoolean = Convert.ToBoolean(nMyInt & 1); bMyBoolean = Convert.ToBoolean(nMyInt & 2); When it will result 0 and when >0? What is the logic behind this operator? What are the diferences between the operator '|'? bMyBoolean = Convert.ToBoolean(nMyInt | 1); bMyBoolean = Convert.ToBoolean(nMyInt | 2); Can we use the &&, || operators and get the same results (possibly with different code)?

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.