Bit

From Oracle FAQ

Jump to: navigation, search

A bit is a binary digit - either a 0 or 1. A byte consists of 8 bits.

BIT operator functions

Oracle provides a bitAND function:

SQL> SELECT bitand(2, 4) FROM dual;
BITAND(2,4)
-----------
          0

To simulate bitOR:

CREATE FUNCTION bitor(x IN NUMBER, y IN NUMBER) RETURN NUMBER AS
BEGIN
    RETURN x + y - bitand(x,y);
END;
/
SQL> SELECT bitor(2, 4) FROM dual;
BITOR(2,4)
----------
         6

To simulate bitXOR:

CREATE FUNCTION bitxor(x IN NUMBER, y IN NUMBER) RETURN NUMBER AS
BEGIN
    RETURN bitor(x,y) - bitand(x,y);
END;
/ 
SQL> SELECT bitxor(2, 4) FROM dual;
BITXOR(2,4)
-----------
          6

Also see


Glossary of Terms
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z #
Retrieved from "http://orafaq.com/wiki/Bit"
Personal tools