Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bitwise exclusive OR in Oracle

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?

like image 403
Schotime Avatar asked Mar 03 '09 00:03

Schotime


People also ask

What is a bitwise exclusive?

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 .

What is Bitwise operator in Oracle?

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.


1 Answers

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

like image 108
MarkusQ Avatar answered Sep 23 '22 01:09

MarkusQ