In C, suppose I have an unsigned char A which can be either 0 or 1. I would like to find a bitwise logical operator that will convert A to !A.
Note: I am using this code on a GPU, where bitwise operators are very cheap compared to logical operators. i.e. XOR is much cheaper than !
If by 'not' you mean send 1 to 0 and 0 to 1. you can use the XOR operator ^
to do that. If character is called c, you can write c = c ^ 1;
.
You should use the "logical not" operator:
A = !A;
You can also use the "bitwise not" operator, but this will make your code harder to understand since what you are doing is actually a logical not:
A = ~A;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With