Reputation: 255
I wonder how does it work in Unix:
user$ i=5
user$ echo $((i &~ 1))
4
what happens inside the parentheses?
Upvotes: 1
Views: 96
Reputation: 255
ok, got it
binary 5 is 101
binary 1 is 001 -> ~1 is 110
101 & 110 -> 100 which is 4 in decimals
Upvotes: 1
Reputation: 785156
Both &
and ~
are bitwise operators.
~1
is unary bitwise negation that produces -2
5 & -2
is binary bitwise AND operation that produces 4Upvotes: 4