S
S
Sergey2021-11-23 20:40:50
C++ / C#
Sergey, 2021-11-23 20:40:50

How do logical operators behave in complex situations?

I'm learning seasharp. There are problems :-(

That's what I understand.

Console.WriteLine(false & true);  // false
Console.WriteLine(1 & 1);            // 1


And I don't understand this!
Console.WriteLine(-2 & -3);         // -4
Console.WriteLine(2 & -2);          // 2
Console.WriteLine(2 & 3);           // 2

What are they doing here?

And yet, why are there such strange compound assignment operators?
+= , *= - no problem here.
But |= , &= - what do they do?

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-11-24
@Shull

These are not exactly logical operators.
These are bitwise operators, and they perform operations on bits.
For example (in binary)
100 | 001 = 101
100 & 111 = 100
110 ^ 011 =
101

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question