I am trying to figure out all of the common bit-wise operations in Oracle.
In SQL Server we have some very simple bit-wise operators to use against a bit-wise value:
&- Evaluates if bit existsselect 10 & 2 /* result=2 */|- Add Bit (if doesn't exist)select 10 | 2 /* result=10 */&~- Remove Bit (if exists)select 10 &~ 2 /* result=8 */^- Toggle Bit (remove if exists, adds if doesn't)select 10 ^ 2 /* result = 8 */
In Oracle, I know we have a built-in bitand() function which is more or less equivalent to SQL Server &, and I have built an Oracle bit-wise OR function to mimic SQL server's bit-wise OR operation (|) as follows:
CREATE OR REPLACE FUNCTION BITOR (x IN NUMBER, y IN NUMBER) RETURN NUMBER AS
BEGIN
RETURN x + y - BITAND(x,y);
END;
My question is: how can I achieve the SQL Server &~ and the ^ operations in Oracle?