How does actually "&~" work? How does actually "&~" work? unix unix

How does actually "&~" work?


Both & and ~ are bitwise operators.

  • ~1 is unary bitwise negation that produces -2
  • 5 & -2 is binary bitwise AND operation that produces 4


ok, got it

binary 5 is 101

binary 1 is 001 -> ~1 is 110

101 & 110 -> 100 which is 4 in decimals