+ 1
If && is AND operator in c++, so what '&' is ? And how to use it ?
3 ответов
+ 16
& is the bitwise AND.
it simply converts numbers to binary, do its job, and then convert output back to initial numeric system.
5 & 7 ->
101 &
111 =
101 -> 5
4 & 1 ->
100 &
001 =
000 -> 0
Rules (vertically):
AND
1 & 1 = 1
1 & 0 = 0
0 & 1 = 0
0 & 0 = 0
OR
1 | 1 = 1
1 | 0 = 1
0 | 1 = 1
0 | 0 = 0
XOR(one or other but not both)
1 ^ 1 = 0
1 ^ 0 = 1
0 ^ 1 = 1
0 ^ 0 = 0
+ 3
Than you @ValentinHacker
and excuse me, i'm biginner, should i know or learn binary of deferent numbers, to use the bitwise functions !?