1

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 exists select 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?

1
  • 4
    BITXOR(x,y) = BITOR(x,y) - BITAND(x,y) = x + y - 2*BITAND(x,y) Aug 2, 2016 at 16:31

1 Answer 1

-1

Have you checked the manual?, it should help with your question to a large extent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.