S
S
SuperDuperPuper2020-07-31 11:31:03
C++ / C#
SuperDuperPuper, 2020-07-31 11:31:03

Why is the value "false" assigned?

bool a = (2&1)!=0;
bool b = (2&2)!=0;
//почему переменная "a" равна "false",а переменная "b" равна "true"?Как это работает ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2020-07-31
@SuperDuperPuper

The binary representation of the number 2 will be 10
The binary representation of the number 1 will be 01
The logical "AND" (operator &) in the first case will return 0 (00), and in the second 2 (10)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question