CREATE OR replace FUNCTION bitor( x IN NUMBER, y IN NUMBER ) RETURN NUMBER AS
BEGIN
RETURN x + y - bitand(x,y);
END;
/
And, once you have both bitand() and bitor(), you can build a bitxor():
CREATE OR replace FUNCTION bitxor( x IN NUMBER, y IN NUMBER ) RETURN NUMBER AS
BEGIN
RETURN bitor(x,y) - bitand(x,y);
END;
/
Finally, for One's complement, you can xor the number with all 1's.
Here's the code for bitcomplement():
create or replace function bitcomplement(x in number, y in number) return number as
begin
return bitxor(x,power(2,y)-1);
end;
/
So, you can do something like:
SQL> select bitcomplement(2,4) from dual;
BITCOMPLEMENT(2,4)
------------------
13
Note that the second argument to bitcomplement is how "wide" the bitfield should be. In this case, it's 4, if you're expecting 13.
Note that the value of the one's complement will depend on how many 1's you're xoring against.
Finally, thanks to Connor McDonald for the bitor() and bitxor() functions. The bitcomplement() function is my own creation.
-Mark