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?
The bitwise exclusive OR operator (in EBCDIC, the ‸ symbol is represented by the ¬ symbol) compares each bit of its first operand to the corresponding bit of the second operand. If both bits are 1 's or both bits are 0 's, the corresponding bit of the result is set to 0 .
The binary | operator is used to set bits in an integer operand. The binary ^ operator returns one in each bit position where exactly one of the corresponding operand bits is set. The shift operators are used to move bits left or right in a given integer operand.
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
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