+ 1
Why is it printing 12 in both case ?
X = 12 Y = 15 Print (X&Y) Print(Y&X)
4 Réponses
+ 7
& is an operator for working with Boolean numbers.
12 is 1100
15 is 1111
+ 3
Just like addition and multiplication, binary AND is commutative, i.e. changing the order of the operands do not change the result of the operation.
https://en.m.wikipedia.org/wiki/Commutative_property
+ 1
12: 1100
15: 1111
Applying the & operator returns 1 for each pair of 1s and 0 for literally anything.
Therefore,
(1&1), (1&1), (0&1), (0&1) returns 1100, or 12.
0
Thank you very much for explaining sir and thanks for thanks for that link too
.