I was looking for a way to do a BITOR() with an Oracle database and came across a suggestion to just use BITAND() instead, replacing BITOR(a,b) with a + b - BITAND(a,b).I tested it by hand a few times and verified it seems to work for all binary numbers I could think of, but I can't think out quick mathematical proof of why this is correct. Could somebody enlighten me?
Take a look at this crude drawing I've made to help conceptualize this (this is a google drive link): https://urlzs.com/AGdXp. Suppose we have 2 domains A and B which we represent with a Venn diagram. The green area is A∪B (read as "a union b") which contain objects that belong to set A or set B. The yellow area is A∩B (read as "a intersection b") which contains objects that belong to set A and set B. Using this graphical approach, it logically follows that A∪B = A + B - A∩B because the green area can be found by adding the area of A and B and subtracting the yellow area. This applies to your situation assuming that | is the xor operator which is equivalent to the union operator.