Oracle – Bitwise exclusive OR in Oracle

bit-manipulationdatabaseoraclestored-procedures

In SQL Server I have been using the ^ symbol, however that doesn't seem to work in Oracle.

How do I do a bitwise exclusive OR in Oracle?

Best Solution

From the docs:

function bitor(p1 number, p2 number) return number is
begin
  return p1-bitand(p1,p2)+p2;
end;

function bitxor(p1 number, p2 number) return number is
begin
  return bitor(p1,p2)-bitand(p1,p2);
end;

To see that these work, follow the logic with just 0s and 1s for input, and then not that there are no borrow or caries.

-- MarkusQ