Search code examples
cbit-manipulationbitwise-operatorsbitwise-and

How to do bitwise ANDING in c using just ~ and |


I need to make a function using just ~ and |, such that function f(6, 5) will return 4 as the answer.


Solution

  • By De Morgan's law, ~(a | b) equals ~a & ~b. By the same law, a & b equals ~(~a | ~b).