https://codeeval.dev/gist/c7d32af417ad7db72bbd9e745869546e
Why
A bit wise XOR
(exclusive or) operates on the bit level and uses the following Boolean truth table:
true OR true = false
true OR false = true
false OR false = false
Notice that with an XOR operation true OR true = false
where as with operations true AND/OR true = true
, hence the exclusive nature of the XOR operation.
Using this, when the binary value for a
(0101
) and the binary value for b
(1001
) are XOR
’ed together we get the binary value of 1100
:
int a = 0 1 0 1
int b = 1 0 0 1 ^
---------
int c = 1 1 0 0
The bit wise XOR does not change the value of the original values unless specifically assigned to using the bit wise assignment compound operator ^=
:
https://codeeval.dev/gist/50441708951506dd98eca9784930b9b2
also in 2015+ compilers variables may be assigned as binary:
int cn = 0b0111;