[Off-topic] ! Inverse operand for number?

As we know this is true
!true -> false
!false -> true

Is there a clever way to do this with numbers? Bitwise or something as to get the result

!1 -> 0
!0 -> 1

Yes. XOR - https://www.arduino.cc/en/Reference/BitwiseAnd
1 ^ 1 -> 0
0 ^ 1 -> 1

This is not inverse operand. But it will do what you need. Inverse operand for number would be Bitwise NOT ~.

1 Like